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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

优先队列讲解

發布時間:2025/4/16 编程问答 14 豆豆
生活随笔 收集整理的這篇文章主要介紹了 优先队列讲解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*程序大意就是在這個優先隊列里依次插入10、8、12、14、6,再輸出。 結果是什么呢? 14 12 10 8 6 也就是說,它是按從大到小排序的!*/ #include<cstdio> #include<queue> using namespace std; priority_queue <int> q; int main() {q.push(10),q.push(8),q.push(12),q.push(14),q.push(6);while(!q.empty())printf("%d ",q.top()),q.pop(); } /*程序大意就是插入(10,100),(12,60),(14,40),(6,20),(8,20)這五個node。 再來看看它的輸出: (14,40) (12,60) (10,100) (8,20) (6,80)*/ #include<cstdio> #include<queue> using namespace std; struct node {int x,y;bool operator <(const node & a) const//const的形式也不能改動{return x<a.x;//從大到小排序}/* bool operator <(const node &a) const{return x>=a.x;//從大倒小}*/ }k; priority_queue <node> q; int main() {k.x=10,k.y=100; q.push(k);k.x=12,k.y=60; q.push(k);k.x=14,k.y=40; q.push(k);k.x=6,k.y=80; q.push(k);k.x=8,k.y=20; q.push(k);while(!q.empty()){node m=q.top(); q.pop();printf("(%d,%d) ",m.x,m.y);} } //less<int>:14 12 10 8 6 //greater<int>:6 8 10 12 14 #include<cstdio> #include<queue> using namespace std; priority_queue <int,vector<int>,less<int> > p; priority_queue <int,vector<int>,greater<int> > q; int a[5]={10,12,14,6,8}; int main() {for(int i=0;i<5;i++)p.push(a[i]),q.push(a[i]);printf("less<int>:")while(!p.empty())printf("%d ",p.top()),p.pop();pritntf("\ngreater<int>:")while(!q.empty())printf("%d ",q.top()),q.pop(); }

總結

以上是生活随笔為你收集整理的优先队列讲解的全部內容,希望文章能夠幫你解決所遇到的問題。

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