STL queue

View Code
 1 #include<iostream>
2 #include<queue>
3 #include<list>
4 #include<deque>
5
6 //queue不能用vector
7 //队列和堆栈都不能修改数据的值,没有迭代器
8
9 using namespace std;
10
11
12 int main()
13 {
14 queue<int, deque<int>> a;
15 queue<int,list<int>> b;
16 queue<int> q;//默认为deque
17
18
19 q.push(10);
20 q.push(5);
21 q.push(-1);
22 q.push(20);
23
24 cout << "现在队列里有 " << q.size() << "个数据"<< endl;
25 cout << "队首的数据: " << q.front() << endl;
26 cout <<"队尾的数据: " << q.back() << endl;
27 q.pop();
28 cout << "pop以后,队首的数据: " << q.front() << endl;
29
30 while(q.size()!=0)
31 {
32 cout << "删除: " << q.front() << endl;
33 q.pop();
34
35
36 }
37
38 if(q.empty())
39 cout << "现在队列是空的!" << endl;
40
41
42 }
posted @ 2012-03-27 23:31  uniquews  阅读(789)  评论(0编辑  收藏  举报