#include <iostream>
#include <queue>
#include <string>
using namespace std;
/** \brief Queue
*@NWNU ziyif
*/
//Queue FIFO
//Queue容器允许从一端push数据,另一端pop数据
//Queue容器只有队头front和队尾back能够被外界访问,所以Queue也不能遍历
class Person{
public:
Person(string name,int age){//second,注意加入string头文件
this->Name=name;
this->Age=age;
}
string Name;//first
int Age;
};
void try1();
int main()
{
try1();
return 0;
}
void try1(){
queue<Person> q;
//数据
Person p1("WESTBROOK",33);
Person p2("ROSE",33);
Person p3("KRYIE",29);
Person p4("CURRY",32);
//push数据
q.push(p1);
q.push(p2);
q.push(p3);
q.push(p4);
//赋值操作
queue<Person>Q=q;
cout<<"Q.size="<<Q.size()<<endl;
//查看队列size
cout<<"q.size="<<q.size()<<endl;
cout<<endl;
//只要Queue不为空,查看front与back,然后pop
while(!q.empty()){
//查看front
cout<<"front.name="<<q.front().Name<<endl<<"front.age="<<q.front().Age<<endl;
//查看back
cout<<"back.name="<<q.back().Name<<endl<<"back.age="<<q.back().Age<<endl;
cout<<endl;
//pop
q.pop();
}
//再次查看队列size
cout<<"q.size="<<q.size()<<endl;
}
Queue容器
最新推荐文章于 2024-08-16 23:08:36 发布