• 【STL】-priority_queue的用法


    初始化:

    priority_queue<int>                           maxPQ;

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

    算法:

     minPQ.push( 4 )

    代码:

     1 #include <iostream>
     2 #include <vector>
     3 #include <queue>
     4 #include <functional>
     5 #include <string>
     6 using namespace std;
     7 
     8 // Empty the priority queue and print its contents.
     9 template <typename PriorityQueue>
    10 void dumpContents( const string & msg, PriorityQueue & pq )
    11 {
    12     cout << msg << ":" << endl;
    13     while( !pq.empty( ) )
    14     {
    15         cout << pq.top( ) << endl;
    16         pq.pop( );
    17     }
    18 }
    19 
    20 // Do some inserts and removes (done in dumpContents).
    21 int main( )
    22 {
    23     priority_queue<int>                           maxPQ;
    24     priority_queue<int,vector<int>,greater<int> > minPQ;
    25 
    26     minPQ.push( 4 ); minPQ.push( 3 ); minPQ.push( 5 );
    27     maxPQ.push( 4 ); maxPQ.push( 3 ); maxPQ.push( 5 );
    28 
    29     dumpContents( "minPQ", minPQ );
    30     dumpContents( "maxPQ", maxPQ );
    31 
    32     return 0;
    33 }

    输出:

    $ ./a.exe
    minPQ:
    3
    4
    5
    maxPQ:
    5
    4
    3
  • 相关阅读:
    期权标的概率密度函数
    Girsanov Theorem
    拉马努金恒等式
    波动率的三类模型
    stack(栈) and heap(堆)
    covar of lognormal variables
    BS 相关的一些近似公式
    布朗运动的一些特殊性质
    排序算法
    Mac node.js
  • 原文地址:https://www.cnblogs.com/dracohan/p/3891237.html
Copyright © 2020-2023  润新知