#include
#include
void Insert();
void Del();
void Display();
typedef struct student node;
struct student
{
int rollno;
int pr;
node *next,*prev;
}*front,*rear,*newrec;
void main()
{
clrscr();
int choice=0,n,i;
while(choice!=4)
{
printf("\n==================Menu===================");
printf("\n| 1. Insert Item into the Priority Queue |");
printf("\n| 2. Delete from the Priority Queue |");
printf("\n| 3. Display the Priority Queue Items |");
printf("\n| 4. Exit the Application |");
printf("\n=========================================");
printf("\n Enter the Choice :->");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("\n HOW MANY ITEMS YOU WANT TO PUSH INTO THE PRIORITY QUEUE :->");
scanf("%d",&n);
for(i=0;i
printf("\n Enter the Priority :");
scanf("%d",&newrec->pr);
newrec->next=NULL;
newrec->prev=NULL;
if(front==NULL)
{
front=newrec;
front->prev=NULL;
}
else
{
rear->next=newrec;
newrec->prev=rear;
}
rear=newrec;
}
void Del()
{
int pri;
node *ptr;
ptr=front;
if(front==NULL)
{
printf("\n Priority Queue is empty");
return;
}
else
{
pri=front->pr;
while(ptr!=NULL)
{
if(pri<=ptr->pr)
pri=ptr->pr;
ptr=ptr->next;
}
ptr=front;
while(ptr!=NULL)
{
if(ptr->pr==pri)
{
if(ptr==front)
{
front->prev=NULL;
front=front->next;
ptr=front;
}
else
{
ptr->prev->next=ptr->next;
ptr->next->prev=ptr->prev;
break;
}
}
ptr=ptr->next;
}
}
}
void Display()
{
node *ptr;
int srno=0;
ptr=front;
if(ptr==NULL)
{
printf("\nPriority Queue is Empty");
return;
}
printf("\n------------------------");
printf("\nSr. No. Record Value Priority");
while(ptr!=NULL)
{
srno++;
printf("\n %d %d %d",srno,ptr->rollno,ptr->pr);
ptr=ptr->next;
}
printf("\n------------------------");
}
No comments:
Post a Comment