#include<iostream>
#include<string>
using namespace std;
#include<queue>
#include<algorithm>
/*队列queue的常见接口
push(),入队
pop(),出队
front(),返回队首元素
back(),返回队尾元素
empty(),判断队是否为空
size(),返回队的大小
queue<int> q;无参构造
queue<int> q2(s);拷贝构造
q3 =q2 = q;operator=重载
*/
void print(int & a) {
cout << a << endl;
}
void test() {
queue<int> q;
q.push(10);
q.push(20);
q.push(30);
q.push(40);
q.pop();
cout << q.back() << endl;
cout<<q.front() << endl;
cout<<q.size() << endl;
cout<<q.empty() << endl;
queue<int> q1(q);
queue<int> q2;
q2 = q1 = q;
cout << q2.back() << endl;
cout << q2.front() << endl;
cout << q2.size() << endl;
cout << q2.empty() << endl;
q.front() = 10;
q.back() = 100;
cout << q.front() << endl;
cout << " ==========" << endl;
while (!q.empty()) {
print(q.front());
q.pop();
}
}
int main() {
test();
return 0;
}
c++队列queue的常见接口
最新推荐文章于 2023-05-28 08:35:24 发布