Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please show all the steps as detail as possible.... I need help with this.... **

ID: 3801192 • Letter: P

Question

Please show all the steps as detail as possible.... I need help with this....

*****************************************************************

Need Help on C++ Programming. Can you show me and teach me how to make this programming.

*Make sure the programming is working and do not turn in a handwriting.

*Do not separate the file, use main.cpp that make me understand how to do this programming. Use "iostream"

*****************************************************************

What is a priority Queue

Give an example in every day life.

*****************************************************************

Program 1 – Implement a Priority Queue(PQ) using an UNSORTED LIST. Use an array size of 10 elements. Use a circular array: Next index after last index is 0. Add the new node to next available index in the array. When you add an element, add 1 to index (hit max index, go to index 0). Test if array in full before you add. When you remove an element, from the list, move the following elements to the left to fill in the blank, etc ( Like prior program done with LISTS )

Explanation / Answer

A Priority Queue is an abstract datatype which is similar to a queue aor a stack, but where in addition each element in the priority queue has a priority associated with it. An element with higher priority is treated beforehand to the element with lower priority. If two elements have the same priority, then the elements are treated in accordance to their order int the priority queue.

Everyday example of Priority Queue:

Each parking light in our simulation would have an event scheduled for its next change. When a light changes to red, we schedule its next change to green some bnumber of seconds later. When a light changes to green, we schedule a change to yellow event some time a later, and so on.

//Program to implement Priority Queue in C++

//include basic libraries

#include<iostream>

#include<conio>

using namespace std;

//Defining Priority Queue

struct node

{

int priority;

int info;

struct node *link; //creating pointer of type struct

};

class pqueue

{

private:

node *front;

public:

pqueue() //default constructor of class pqueue

{

front=NULL;

}

//Inserting in Priority Queue

void insert(int item, int priority)

{

node *temp, *q;

temp=new node;

temp->info=item;

temp->priority=priority;

if(front==NULL || priority<front->priority){

temp->link=front;

front=temp;

}

else

{

q=front;

while(q->link!=NULL && q->link->priority <= priority)

q=q->link;

temp->link=q->link;

q->link=temp;

}

}

//Deleting from Priority Queue

void del()

{

node *temp;

if(front==NULL)

cout<<" Queue Underflow ";

else

{

temp=front;

cout<<' Deleted Item is:"<<temp->info<<endl;

front=front->link;

free(temp);

}

}

//Prinitng Priority Queue

void display()

{

node *ptr;

ptr=front;

if(front==NULL)

cout<<" Queue is Empty.";

else

{

cout<<" Queue is:";

cout<<" Priority Item:";

while(ptr!=NULL)

{

cout<<ptr->priority<<" <<"ptr->info<<endl;

ptr=ptr->link;

}

}

}

};

//Main Function

int main()

{
int choice, item, priority;

pqueue obj1;

do

{

cout<<" 1.Insert";

cout<<" 2.Delete";

cout<<" 3.Display";

cout<<" 4.Quit";

cout<<" Enter your choice:";

cin>>choice;

switch(choice)

{

case 1: cout<<" Input value to be added into queue:";

cin>>item;

cout<<" Enter its priortiy:";

cin >>priority;

obj1.insert(item,priority);

break;

case 2: obj1.del();

break;

case 3: obj1.display();

break;

case 4: break;

default: cout<<" You entered wrong choice";

}

}

while(choice!=4);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote