Skip to content

Commit 52ceacc

Browse files
authored
Priority Queue#238
Priority Queue
2 parents a22b790 + 2095887 commit 52ceacc

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Title: Priority Queue in c++
3+
Priority Queue is an extension of queue.
4+
It is designed such that all elements in the queue are in non increasing order.
5+
While dequeue, an element with high priority is dequeued before an element with low priority.
6+
Function used: priorityQueue.top(), priorityQueue.push(), priorityQueue.empty(), priorityQueue.pop(), priorityQueue.size()
7+
Author: Sharmila
8+
*/
9+
10+
#include <iostream>
11+
#include <queue>
12+
13+
using namespace std;
14+
15+
void showPriQueue(priority_queue <int> pri_queue) {
16+
while (!pri_queue.empty()){
17+
cout << pri_queue.top()<<" ";
18+
pri_queue.pop();
19+
}
20+
}
21+
22+
int main (){
23+
priority_queue <int> myqueue;
24+
int number_values;
25+
26+
cout << "Enter the total number of element: ";
27+
cin >> number_values;
28+
29+
for (int index = 0; index < number_values; index++) {
30+
myqueue.push(index);
31+
}
32+
33+
cout << "Values in myqueue : ";
34+
showPriQueue(myqueue);
35+
cout << "\nSize of myqueue : " << myqueue.size() << endl;
36+
cout << "First element of the myqueue : " << myqueue.top() << endl;
37+
cout << "Pop element from myqueue ";
38+
myqueue.pop();
39+
cout << "\nValues in myqueue after pop : ";
40+
showPriQueue(myqueue);
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)