首页 > 其他 > 详细

自定义优先队列

时间:2015-06-07 14:33:57      阅读:249      评论:0      收藏:0      [点我收藏+]
 1 #include<stdio.h>
 2 #include<queue>
 3 using namespace std;
 4 
 5 
 6 struct node
 7 {
 8     friend bool operator< (node x,node y)
 9     {
10         return x.pre>y.pre;// > 表示从小到大,< 表示从大到小;根            据pre来判优先度;
11     }
12     int pre;
13     int val;
14 };
15 
16 int main()
17 {
18     int i,j;
19     node a[1000];
20     int n;
21     priority_queue<node>q;
22     while(scanf("%d",&n)!=EOF)
23     {
24         node z;
25         for(i=0;i<n;i++)
26         {
27             scanf("%d%d",&a[i].pre,&a[i].val);
28             q.push(a[i]);
29         }
30         while(!q.empty())
31         {
32             node x;
33             x=q.top();
34             printf("%d %d\n",x.pre,x.val);
35             q.pop();
36         }
37         
38         printf("\n");
39     }
40 }
41         

 

自定义优先队列

原文:http://www.cnblogs.com/sweat123/p/4558400.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!