Code:
#include iostream
#include queue
#include string
#include cstdlib
using namespace std;
int main()
{
priority_queue
int choice, item;
while (1)
{
cout<<"\n---------------------"<
cout<<"Priority Queue Implementation in Stl"<
cout<<"\n---------------------"<
cout<<"1.Insert Element into the Priority Queue"<
cout<<"2.Delete Element from the Priority Queue"<
cout<<"3.Size of the Priority Queue"<
cout<<"4.Top Element of the Priority Queue"<
cout<<"5.Exit"<
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 "<
}
else
{
cout<<"Priority Queue is Empty"<
}
break;
case 3:
cout<<"Size of the Queue: ";
cout<
break;
case 4:
cout<<"Top Element of the Queue: ";
cout<
break;
case 5:
exit(1);
break;
default:
cout<<"Wrong Choice"<
}
}
return 0;
}
Output:
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 1
Enter value to be inserted: 5
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 1
Enter value to be inserted: 3
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 1
Enter value to be inserted: 7
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 1
Enter value to be inserted: 4
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 1
Enter value to be inserted: 2
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 1
Enter value to be inserted: 8
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 3
Size of the Queue: 6
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 4
Top Element of the Queue: 8
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 2
Element 8 Deleted
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 3
Size of the Queue: 5
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 4
Top Element of the Queue: 7
---------------------
Priority Queue Implementation in Stl
---------------------
1.Insert Element into the Priority Queue
2.Delete Element from the Priority Queue
3.Size of the Priority Queue
4.Top Element of the Priority Queue
5.Exit
Enter your Choice: 5
------------------
(program exited with code: 1)
Press return to continue
More C++ Programs: