//queue的使用
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<queue>
using namespace std;
/*
引用头文件 #include<queue>
queue类本身是一个类模板
C++队列是一种容器适配器,它给予程序员一种先进先出(FIFO)的数据结构。
1.back() 返回一个引用,指向最后一个元素
2.empty() 如果队列空则返回真
3.front() 返回第一个元素
4.pop() 删除第一个元素
5.push() 在末尾加入一个元素
6.size() 返回队列中元素的个数
*/
class Student{
public:
int age;
char name[30];
};
void Print(queue<Student *> &qt){
while (!qt.empty()){
//获取第一个元素
Student * temp = qt.front();
//打印信息
cout << "学生姓名:" << temp->name << ";学生年龄是:" << temp->age << endl;
//弹出元素
qt.pop();
}
}
void ProtectA(){
Student s1, s2, s3;
s1.age = 12;
strcpy(s1.name, "小米");
s2.age = 14;
strcpy(s2.name, "小红");
s3.age = 16;
strcpy(s3.name, "小刚");
//定义队列
queue<Student *> myq;
myq.push(&s1);
myq.push(&s2);
myq.push(&s3);
Print(myq);
}
void main(){
ProtectA();
system("pause");
}