0% found this document useful (0 votes)
7 views3 pages

Data Structure-76-78

Uploaded by

briley.boede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Data Structure-76-78

Uploaded by

briley.boede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

scanf("%d",&item_prty);

temp->priority=item_prty;
temp->info=item;
if(front==NULL||item_prty>front->priority)
{
temp->link=front;
front=temp;
}
else
{
q=front;
while (q->link!=NULL &&q->link-> priority >=item_prty)
q=q->link;
temp->link=q->link;
q->link=temp;
}
}
void deletion()
{ if(front==NULL)
printf("Queue is underflow");
else
{
temp=front;
printf("Deleted item is %d\n",
temp->info);
front=front->link;
free(temp);
}
}
void display()
{
ptr=front;
if(front==NULL)
printf("Queue is underflow");
else
{
printf("Queue is :\n");
printf("priority item :\n");
while(ptr!=NULL)
{
printf("%5d %5d\n",ptr->priority,ptr->info);
ptr=ptr->link;

}
}
}

OUTPUT:

74
1 - Insert an element into queue
2 - Delete an element from queue
3 - Display queue elements
4 - Exit
Enter your choice: 1

Enter value to be inserted: 20


Enter your choice: 1
Enter value to be inserted: 45
Enter your choice: 1
Enter value to be inserted: 89
Enter your choice: 3
89 45 20
Enter your choice: 1
Enter value to be inserted: 56
Enter your choice: 3
89 56 45 20
Enter your choice: 2
Enter value to delete: 45
Enter your choice: 3
89 56 20
Enter your choice: 4

Program: (b)
#include<stdio.h>
#include<conio.h>
#define max 3
int q[max],rear=-1,front=-1;
void main()
{ int ch;
clrscr();
do
{ printf("\nqueue implementation\n");
printf("1.insert 2.delete 3.display 4.exit\n");
printf("enter your choice\n");
scanf("%d",&ch);
switch(ch)
{ case 1:insert(); break;
case 2:delete(); break;
case 3:display(); break;
case 4:exit(1);
default:printf("wrong choice\n"); break;
}
}while(ch<=4);
getch();
}
insert()
{ int item;

75
if(rear==max-1)
{ printf("queue overflow\n"); }
else
{ if(front==-1)
front=0;
printf("insert the element in queue:");
scanf("%d",&item);
rear++;
q[rear]=item;
}
}
delete()
{ if(front==-1)
{ printf("queue underflow\n");
}
else
{ printf("element deleted from queue is:%d\n",q[front]);
front++;
if(front==max)
front=rear=-1;
}
}
display()
{ int i;
if(front==-1)
printf("queue is empty\n");
else
{ printf("queue is :\n");
for(i=front;;i++)
{ printf("%2d",q[i]);
if(i==rear)
return;
} } }

OUTPUT:
1. Insert
2. Delete
3. Display
4. Exit
Enter your choice:1
Enter element to cqueue: 10
1. Insert
2. Delete
3. Display
4. Exit
Enter your choice: 1
Enter element to circular queue: 20
1. Insert
2. Delete

76

You might also like