单向队列
作者:
_saule | 来源:发表于
2017-08-05 09:32 被阅读0次
示意图:

单向队列示意图
代码:
#include<iostream>
#include<queue>
using namespace std;
int main(){
queue<int> q1;
for (int i = 0; i < 10; i++){
q1.push(i);
cout << "push: " << i << endl;
cout << "front of the queue: " << q1.front() << endl;
cout << "back of the queue: " << q1.back() << endl;
}
if (!q1.empty()){
cout << "this is unempty queue"<<endl;
}
cout <<"size of queue(10):"<< q1.size() << endl;
cout << "front of the queue(0): " << q1.front() << endl;
cout << "back of the queue(9): " << q1.back() << endl;
int size = q1.size();//for 循环中的size在变。
for (int j = 0; j < size; j++){
cout << "current front: " << q1.front() << endl;
q1.pop();
}
if (q1.empty()){
cout << "this is a empty queue." << endl;
}
system("PAUSE");
return 0;
}
本文标题:单向队列
本文链接:https://www.haomeiwen.com/subject/srjilxtx.html
网友评论