C++ Program to Implement Priority Queue
// C++ program to demonstrate the use of priority_queue
#include <iostream>
#include <queue>
using namespace std;
// driver code
int main()
{
int arr[6] = { 7, 2, 4, 8, 6, 9 },i;
// defining priority queue
priority_queue<int> pq;
// printing array
cout << "Array: ";
for (i=0;i<6;i++)
{
cout << arr[i] << ' ';
}
cout << endl;
// pushing array sequentially one by one on priority
for (int i = 0; i < 6; i++) {
pq.push(arr[i]);
}
// printing priority queue
cout << "Priority Queue: ";
while (!pq.empty()) {
cout << pq.top() << ' ';
pq.pop();
}
return 0;
}
Comments
Post a Comment