here is the code/ also here [pastebin code list][1]: https://pastebin.ubuntu.com/p/h6gM8yP8Q2/
I want to implement a priority queue (insert, delete, find) project with a switch case for my assignment please can anyone help me?
Actually, I am trying to do using queue into switch case
- add new entry by gquiz.push()
- delte gquiz.pop()
- find gquiz.top() //minumum value will show
i already added the code option but maybe gquiz.pop() not work in the switch case. if not then how I will do that?
Please, help to solve the project.
Thank you.
#include<bits/stdc++.h>
#include <iostream>
#include <queue>
using namespace std;
void showpq(
priority_queue<int, vector<int>, greater<int> > gq)
{
priority_queue<int, vector<int>,greater<int> > g = gq;
while (!g.empty()) {
cout << '' << g.top();
g.pop();
}
cout << '
';
}
int main()
{
priority_queue<int, vector<int>,greater<int> > gquiz;
while(1)
{
int choice;
cout<<"what do you want to do?
"
"
"
"1. Insert
"
"2. Find
"
"3. Delete
"
"4. Show Queue
choice your option from above: ";
cin>>choice;
switch(choice)
{
case 1:
int n;
cout<<"Enter the value: " ;
cin>>n;// Option 2 => Insert
gquiz.push(n);
break;
case 2:
gquiz.top();
if(!gquiz.empty()){
gquiz.top(); // Find the minimum number.
}else{
cout<<"Empty Priority Queue"<<endl;
}
break;
case 3:
if(!gquiz.empty()){
gquiz.pop(); //Delete the minimum number from the queue
cout<<"Successfully Deleted"<<endl;
}else{
cout<<"There is not element to delete"<<endl;
}
break;
case 4:
if(!gquiz.empty()){
showpq(gquiz); // Show full queue
}else{
cout<<"There is not element to delete"<<endl;
}
break;
default:
cout<<"
You are terminated!!!
You entered wrong input.
"<<endl;
}
}
return 0;
}
question from:
https://stackoverflow.com/questions/65649058/i-want-to-implement-priority-queue-insert-delete-find-project-with-switch-case 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…