priority_queue-all priority_que functions

////////////////////////////////////////
//      2018/05/08 22:57:50
//      priority_queue-all priority_que functions

// Priority Queues are like queues,but the elements inside the data structor are 
// order by some predicate.

#include <iostream>
#include <queue>
#include <vector>
#include <string>

using namespace std;

int main(){
    priority_queue<int, vector<int>, less<int>> ipq;
    ipq.push(100);
    ipq.push(200);
    ipq.push(300);

    cout << "size of priority_queue ipq  = " << ipq.size() << endl;

    cout << "ipq<int, vector<int>, less<int>> = ";
    while (!ipq.empty()){
        cout << ipq.top() << " ";
        ipq.pop();
    }
    cout << endl;

    cout << "priority_queue<string,vector<string>> spq" << endl;

    priority_queue<string, vector<string>> spq;
    for (int i = 1; i < 10; i++){
        spq.push(string(i,'*'));
    }

    while (!spq.empty()){
        cout << spq.top() << endl;
        spq.pop();
    }
    return 0;
}


/*
OUTPUT:
    size of priority_queue ipq  = 3
    ipq<int, vector<int>, less<int>> = 300 200 100
    priority_queue<string,vector<string>> spq
    *********
    ********
    *******
    ******
    *****
    ****
    ***
    **
    *
*/ 
原文地址:https://www.cnblogs.com/laohaozi/p/12537807.html