I am looking at implementing a priority queue with an added requirement, a find/search function which will tell whether an item is anywhere within the queue. So the functions wi
Please, check this code. I coded this program and this is a priority queue with your needed functions.
1. Insert
2. Find
3. Delete
4. Show
You can try it. It's working perfectly. Here I added ascending order minimum number to maximum number.
I used the priority queue default function to do that with a switch case.
queue.push()
queue.pop()
queue.top()
queue.size()
C++ code:
#include
#include
using namespace std;
void show_queue(
priority_queue, greater > data)
{
priority_queue,greater > myq = data;
while (!myq.empty()) {
cout << '\t' << myq.top();
myq.pop();
}
cout << '\n';
}
int main()
{
priority_queue,greater > myp_queue;
while(1)
{
int choice;
cout<<"\nwhat do you want to do?"<>choice;
switch(choice)
{
case 1:
int n;
cout<<"Enter the value: " ;
cin>>n;// Option 2 => Insert
myp_queue.push(n);
break;
case 2:
if(!myp_queue.empty()){
cout<<"\n"<