-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathpriority-queue-stl.cpp
More file actions
119 lines (60 loc) · 1.8 KB
/
priority-queue-stl.cpp
File metadata and controls
119 lines (60 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* C++ Program to Implement Priority_queue in Stl
*/
#include <iostream>
#include <queue>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
priority_queue<int> pq;
int choice, item;
while (1)
{
cout<<"\n---------------------"<<endl;
cout<<"Priority Queue Implementation in Stl"<<endl;
cout<<"\n---------------------"<<endl;
cout<<"1.Insert Element into the Priority Queue"<<endl;
cout<<"2.Delete Element from the Priority Queue"<<endl;
cout<<"3.Size of the Priority Queue"<<endl;
cout<<"4.Top Element of the Priority Queue"<<endl;
cout<<"5.Exit"<<endl;
cout<<"Enter your Choice: ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"Enter value to be inserted: ";
cin>>item;
pq.push(item);
break;
case 2:
item = pq.top();
if (!pq.empty())
{
pq.pop();
cout<<"Element "<<item<<" Deleted"<<endl;
}
else
{
cout<<"Priority Queue is Empty"<<endl;
}
break;
case 3:
cout<<"Size of the Queue: ";
cout<<pq.size()<<endl;
break;
case 4:
cout<<"Top Element of the Queue: ";
cout<<pq.top()<<endl;
break;
case 5:
exit(1);
break;
default:
cout<<"Wrong Choice"<<endl;
}
}
return 0;
}