1.定义
他是一种先进先出的数据结构,有两个出口。
队尾只能进数据,队头只能出数据。
只允许访问队头队尾的元素,也就是不允许随机访问。
2.接口
1.函数原型
empty队列为空返回true,不为空返回false
2.案例演示
#include<stdio.h>
using namespace std;
#include<queue>
#include<string>
#include <algorithm>
#include <iostream>
class person
{
public:
person(double score, string name)
{
this->score = score;
this->name = name;
}
double score;
string name;
};
void creatperson(queue<person>& v)
{
string s = "ABCDE";
for (int i = 0; i < 5; i++)
{
string name = "选手";
name += s[i];
int score = i+60;
person p(score, name);
v.push(p);
}
}
int main()
{
queue<person>v;
creatperson(v);
cout << v.size() << endl;
for (int i = 0; i < v.size(); i++)
{
cout << "队头" << v.front().name << " " << v.back().score << endl;
cout << "队尾" << v.front().name << " " << v.back().score << endl;
v.pop();
}
cout << v.size() << endl;
return 0;
}