ickchen2

优先队列

#include <queue>
#include <iostream>
#include <vector>
#include <time.h>
using namespace std;
void main(void)
{
priority_queue<int,vector<int>,greater<int> > que;
priority_queue<float,vector<float>,less<int> > que1;
srand((unsigned) (time)(NULL));
for(int i = 1; i <= 20; i++)
{
    int key = rand()%100;
    que.push(key);
    que1.push(key);
}
while(!que.empty() && !que1.empty())
{
int m = que.top();
float mm = que1.top();
cout<<m<<"\t"<<mm<<endl;
que.pop();
que1.pop();
}
cout<<endl;
}

-----------------

0       88
3       73
5       72
6       71
9       70
10      70
13      66
25      58
29      51
33      44
44      33
51      29
58      25
66      13
70      10
70      9
71      6
72      5
73      3
88      0

Press any key to continue

posted on 2008-08-17 17:31 神之子 阅读(105) 评论(0)  编辑 收藏 引用 所属分类: STL


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜