zoukankan      html  css  js  c++  java
  • Priority Queues

    由小到大

    #include <iostream>

    #include <queue>

    #include <vector>

    using namespace std;

    int main()

    {        

           priority_queue < int,    vector<int> , greater<int>  >   q;     

                              q.push(3);      

                              q.push(2);

                              q.push(1);

                             q.push(7);

     while ( !q.empty())    

         {  

                  cout<<q.top()<<endl;            

                          q.pop();    

              }    

    return 0;

    }

    //由大到小

    #include <iostream>

    #include <queue>

    using namespace std;

    int main()

    {    

    priority_queue <int>  q;    

                  q.push(3);   

                 q.push(2);

                 q.push(1);

                q.push(7);

    while ( !q.empty())    

        {        

                      cout<<q.top()<<endl;     

                               q.pop();    

        }    

    return 0;

    }

    ************************************************************************************************

    #include <iostream>
    #include <queue>
    using namespace std;
    int main()
    {
        priority_queue<int> q;
        for(int i = 1;i <= 5;i++)
        {
            q.push(i);
        }
        for(int i = 0;i < 5;i++)
        {
            cout<<q.top()<<endl;
            q.pop();
        }
        return 0;
    }

    ************************************************************************************************************************

    #include <iostream>

    #include <queue>

    using namespace std;

    int main()

    {    

                        priority_queue<int> q;   

                    int i;    

       while (cin>>i)

              q.push(i);

        cout<<q.top()<<endl;

                  q.pop();

        return 0;

    }

  • 相关阅读:
    WHERE col1=val1 AND col2=val2;index exists on col1 and col2, the appropriate rows can be fetched directly
    MySQL 交集 实现方法
    MBProgressHUD的使用
    Xcode4 使用 Organizer 分析 Crash logs(转)
    SimpleXML 使用详细例子
    PHP的XML Parser(转)
    iPhone,iPhone4,iPad程序启动画面的总结 (转)
    Pop3得到的Email 信件格式介绍
    yii总结
    隐藏Tabbar的一些方法
  • 原文地址:https://www.cnblogs.com/2014acm/p/3876657.html
Copyright © 2011-2022 走看看