forked from dharmanshu1921/Daa-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPRIORQUE.C
More file actions
92 lines (92 loc) · 1.49 KB
/
PRIORQUE.C
File metadata and controls
92 lines (92 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include<stdio.h>
#include<malloc.h>
struct node
{
int priority;
int info;
struct node *next;
}*front=NULL;
main()
{
int choice;
while(1)
{
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Display\n");
printf("4.Quit\n");
printf("Enter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("Wrong choice\n");
}
}
}
insert()
{
struct node *temp,*ptr;
int item,prior;
temp=(struct node*)malloc(sizeof(struct node));
printf("\n Enter item to be added in the queue= ");
scanf("%d",&item);
printf("\n Enter priority value= ");
scanf("%d",&prior);
temp->info=item;
temp->priority=prior;
if(front==NULL||prior<front->priority)
{
temp->next=front;
front=temp;
}
else
{
ptr=front;
while(ptr->next!=NULL&&ptr->next->priority<=prior)
ptr=ptr->next;
temp->next=ptr->next;
ptr->next=temp;
}
};
del()
{
struct node *temp;
if(front==NULL)
printf("\nQueue Underflow");
else
{
temp=front;
printf("\nDeleted item is %d",temp->info);
front=front->next;
free(temp);
}
}
display()
{
struct node *ptr;
ptr = front;
if(front==NULL)
printf("\n Queue is empty");
else
{
printf("\n Queue is=");
printf("\nPriority Item");
while(ptr!=NULL)
{
printf("\n%5d %5d",ptr->priority,ptr->info);
ptr=ptr->next;
}
}
}