|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
A dream that you don't fight for can haunt you for rest of your life.
Queue
Queue是一种先进先出的数据结构,他有两个出口;
队列容器允许从一端新增元素,从另一端移除元素;
队列中只有队头和队尾才可以被外界使用,因此队列不允许有遍历行为;
队列中进数据称为——入队 push
队列中出数据称为——出队 pop
- #include<iostream>
- #include<queue>
- using namespace std;
- void test1()
- {
- //入队——push
- //出队—— pop
- //返回队头元素——front
- //返回队尾元素—— back
- //判断队是否为空—— empty
- //返回队列大小—— size
- queue<int> q1;
-
- q1.push(100);
- q1.push(200);
- q1.push(300);
- q1.push(400);
-
- while( !q1.empty() )
- {
- cout << "队头元素是: " << q1.front() << endl;
- cout << "队尾元素是: " << q1.back() << endl;
-
- q1.pop();
- }
- cout << "队列大小为: " << q1.size() << endl;
- }
- int main()
- {
- test1();
-
- return 0;
- }
复制代码

|
评分
-
查看全部评分
|