00001
00016 #include <iostream>
00017 #include <queue>
00018 #include <vector>
00019 #include <cstdlib>
00020 #include <ctime>
00021
00022 using namespace std;
00023
00024 int main()
00025 {
00026
00027 priority_queue<int, vector<int> > pq;
00028
00029
00030 vector<int> vheap;
00031
00032
00033 vector<int>::iterator iter;
00034
00035
00036 srand(time(0));
00037
00038
00039
00040
00041 for (int i=0; i < 25; i++)
00042 {
00043 int j = rand() % 25;
00044 pq.push(j);
00045 vheap.push_back(j);
00046 push_heap(vheap.begin(), vheap.end(), greater<int>() );
00047 }
00048
00049
00050
00051 cout << "Original numbers: " << endl;
00052 for (iter = vheap.begin(); iter != vheap.end(); iter++)
00053 cout << *iter << " ";
00054
00055
00056 cout << endl << "Priority queue: " << endl;
00057 while (!pq.empty())
00058 {
00059 cout << pq.top() << " ";
00060 pq.pop();
00061 }
00062
00063
00064 cout << endl << "Heap: " << endl;
00065 while (!vheap.empty())
00066 {
00067 cout << vheap[0] << " ";
00068 pop_heap(vheap.begin(), vheap.end(), greater<int>());
00069 vheap.pop_back();
00070 }
00071
00072 cout << endl;
00073
00074 return 0;
00075 }