c++STL学习视频
https://www.bilibili.com/video/av63384955?from=search&seid=5013240884410317680
#include<iostream>
#include <queue>
using namespace std;
class teacher
{
public :
int age;
char name[32];
void printf()
{
cout<<age<<endl;
}
};
void int_queue()
{
queue <int> q;
q.push(1);
q.push(2);
q.push(3); //push(元素)
q.front() ;
q.size();
while(!q.empty())
{
cout<<q.front()<<endl;
q.pop();
}
}
void teacher_queue()
{
teacher t1,t2,t3;
t1.age=31;
t2.age=19;
t3.age=45;
queue <teacher> q; //队列创建
q.push(t1);//入队
q.push(t2);
q.push(t3);
while(!q.empty())
{
teacher tmp;
tmp=q.front();//出队但不删除
tmp.printf();
q.pop();//从队列中删除
}
}
void teacher_queue2()
{
teacher t1,t2,t3;
t1.age=31;
t2.age=19;
t3.age=45;
queue <teacher*> q;
q.push(&t1);
q.push(&t2);
q.push(&t3);
while(!q.empty())
{
teacher* tmp;
tmp=q.front();//出来的不是元素,而是元素的地址
tmp->printf();//指针不能用.用->访问
q.pop();
}
}
int main()
{
int_queue();
teacher_queue();
teacher_queue2();
return 0;
}