newplan

阿基米德在洗澡時發現浮力原理,高興得來不及穿㆖褲子,跑到街㆖大喊:Eureka(我找到了)。
posts - 39, comments - 26, trackbacks - 0, articles - 4
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

priority_queue 简单实例

Posted on 2008-05-07 15:26 山泉弯延 阅读(295) 评论(0)  编辑 收藏 引用
#include <iostream>
#include 
<queue>//有priority_queue
using namespace std;  
class cl
{
      
public:
             
int i;
             
};
bool operator
>(const cl&a, const cl & b)
{
     return a.i 
< b.i;    
}
bool operator
<(const cl&a,const cl &b)
{
     return a.i
>b.i;
}
int main()
{
    
    
    priority_queue
<cl,vector<cl>,greater<vector<cl>::value_type> > q;
    cl a;
    
while(cin>>a.i)
    {
        q.push(a);
    }
    
while(!q.empty())
    {
        cout
<<q.top().i<<endl;
        q.pop();
    }
    system(
"PAUSE");
    return 
1;
}

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