日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

STL12-queue容器

發布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 STL12-queue容器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

queue容器 隊列容器 先進先出

隊列只能在一端插入 一端刪除

隊列不能遍歷 不提供迭代器 不支持隨機訪問

#if 1 #include<iostream> #include<queue> using namespace std; void test01() {queue<int> q; //創建隊列queue<int> q2(q);q.push(10);q.push(20);q.push(30);q.push(40);cout << "隊尾:"<<q.back() << endl;cout << "隊頭:"<<q.front() << endl;while (!q.empty()) {cout << q.front() << endl;q.pop(); //刪除隊頭} } //作業1 queue容器存放對象指針 //作業2 queue容器存放stack容器 int main() {test01();return 0; } #endif

作業:

#if 1 #include<iostream> #include<queue> #include<stack> using namespace std; class Person { public:Person(int Age, int Id) :age(Age), id(Id) {} public:int age;int id; }; //作業1 queue容器存放對象指針 void test01() {queue<Person*> q;Person p1 = { 23,1 };Person p2 = { 24,2 };Person p3 = { 25,3 };q.push(&p1);q.push(&p2);q.push(&p3);while (q.size() > 0) {Person *p = q.front();cout << (*p).age << " " << (*p).id << endl;q.pop();}} //作業2 queue容器存放stack容器 void test02() {stack<Person> sp1;Person p1 = { 23,1 };Person p2 = { 24,2 };Person p3 = { 25,3 };sp1.push(p1);sp1.push(p2);sp1.push(p3);stack<Person> sp2 = sp1;queue<stack<Person>> q;q.push(sp1);q.push(sp2);cout << "queue中stack數為:" << q.size() << endl;while (!q.empty()) {stack<Person> s=q.front();cout << "stack數據內容為:" << endl;while (!s.empty()) {Person p = s.top();s.pop();cout << p.age << " " << p.id << endl;}q.pop();} }int main() {cout << "test01:queue容器存放對象指針" << endl;test01();cout << "test02:queue容器存放stack容器" << endl;test02();return 0; } #endif

總結

以上是生活随笔為你收集整理的STL12-queue容器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。