Library function Priority Queue (priority_queue) output minimum value code
This address: Http://blog.csdn.net/caroline_wendy
The library function Priority queue (Priority_queue) is implemented by the heap (heap), which defaults to the output maximum value .
Output minimum value, need to specify the number of parameters, priority_queue<int, vector<int>, greater<int> >
Code:
/* * main.cpp * * Created on:2014.7.20 * author:spike *//*eclipse CDT, gcc 4.8.1*/#include <stdio.h> #inclu De <queue> #include <vector> #include <functional>using namespace Std;int main (void) {Priority_queue <int, Vector<int>, greater<int> > Pque;pque.push (3);p Que.push (5);p Que.push (1);p Que.push (4); while (!pque.empty ()) {printf ("%d", Pque.top ());p que.pop ();} printf ("\ n"); return 0;}
Output:
C + +-Library function Priority Queue (priority_queue) output minimum value code