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

Priority queue Task For this assignment you are to create a C++ class that will

ID: 3786903 • Letter: P

Question

Priority queue

Task

For this assignment you are to create a C++ class that will implement a priority queue. For your queue low numbers will take highest priority. Your class should implement the following functions

-          Void enq(int)

-          Void deq()

-          Void front()

-          Bool isEmpty()

-          Void printq()

Your program will take in a command file called “cmd.txt” which will instruct your program what operations to run

File Format

<0 or 1 arguments>

Commands

-          1              enq

-          2              deq

-          3              front

-          4              isEmpty

-          5              printq

Example File

1 5

5

1 4

5

1 3

5

1 2

5

1 1

5

1 30

5

3

2

5

2

5

3

Expectations

You should not use any already implemented code such as a library for your linked list

Your code should be well formatted with proper spacing and proper naming

Your code should have well named variables. No a’s b’s or c’s as names unless it is for something like a loop counter

Your code MUST have the same output formatting you see below

Your file MUST be named a3.cpp

My example file does not cover all possible cases your program may be tested against. It is up to you to think about and consider any edge cases that may come up and cause your program to crash.

Front 5 Back Front 5 4 K Back Front 5 4 3 K-- Back Front 5 4 3 2 Back Front 5 4 3 2 1 Back Front 5 4 3 2 1 30 Back Front: 1 DEQ: 1 Front 5 4 3 2 30 Back DEQ: 2 Back Front 5 4 3 30 Front 3

Explanation / Answer

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

void insert();
int deletee();
void display();
struct queue
{
int no;
struct queue *next;
}
*start=NULL;
typedef struct stack st;
void main()
{
int choice,item;
char ch;
clrscr();
do
{
printf("Enter your option ");
printf("1 . push ");
printf(" 2 . deleation ");
printf("3 . display ");
scanf("%d",&choice);

switch(choice)
{
   case 1: insert();
       break;
   case 2: item=deletee();
       printf("Deleted element is = %d ",item);
       break;
   case 3: display();
   break;
   default:printf("You entered wrong choice");
}
printf(" Do you wish to continue");
fflush(stdin);
scanf("%c",&ch);
}
while(ch=='y' || ch=='Y');
}


void insert()
{
struct queue *p,*temp;
printf("%d",start);
temp=start;
p=(struct queue*)malloc(sizeof(struct queue));
printf("Enter number");
scanf("%d",&p->no);
printf("&p=%d ",&p->next);
p->next=NULL;
printf("p=%d ",p);
if(start==NULL)
{
start=p;
printf("s=%d ",start);
}
else
{
while(temp->next!=NULL)
{
printf("t=%d",temp->next);
temp=temp->next;
}
printf("p=%d",p);
temp->next=p;
}
}

int deletee()
{
struct queue *temp;
int value;
if(start==NULL)
{
printf("queue is empty");
getch();
exit(0);
}
else
{
temp=start;
value=temp->no;
start=start->next;
free(temp);
}
return(value);
}

void display()
{
struct queue *temp;
temp=start;
while(temp->next!=NULL)
{
printf(" no= %d",temp->no);
temp=temp->next;
}
printf(" no= %d",temp->no);
}

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