最近写概要设计头有点大,写点博客轻松下。。
c++队列是一种容器适配器,创建一个线性int型队列如:queue<list<int>> q;或双向int型队列:queue<deque<int>>;如果是结构体或者类,把int替换掉就行。整个例子看下:
#include <queue> #include <iostream> using namespace std; struct MyStruct{ int num; };//c++里,结构体和类几乎等同作用。习惯上数据结构不带函数玩 int main() { queue<MyStruct> q; MyStruct s1; s1.num = 66; q.push(s1); MyStruct s2; s2.num = 88;
MyStruct s1copy = q.front(); //在c++里,struct本身是一种类,声明处可以省掉typedef,这点与c有所区别 MyStruct s2copy = q.back(); cout << "s1 front :" << s1copy.num << endl; cout << "s2 back :" << s2copy.num << endl; for(int i = 0; i < q.size(); i++)q.push(s2);
{
q.pop();
} if (q.empty()) { cout << "empty " << endl; } system("pause"); return 0;} 双向队列与此类似。参考:https://zhidao.baidu.com/question/391736530649872125.html