-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha7.c
128 lines (114 loc) · 2.11 KB
/
a7.c
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//Priority Queue
#include<stdio.h>
#include<stdlib.h>
int hpq[10],lpq[10],fronth=-1,rearh=-1,frontl=-1,rearl=-1,sizeh,sizel;
void insert(int *queue,int *front,int *rear,int *size,int data)
{
if(*rear==*size-1)
{
printf("\nQueue Overflow\n");
return;
}
if(*rear==-1)
*front=0;
queue[++*rear]=data;
}
void delete()
{
if(rearh==-1)
{
if(rearl==-1)
{
printf("\nBoth Queues are Empty!\n");
return;
}
printf("Deleted Element from Low PQ is %d\n",lpq[frontl]);
if(frontl==rearl)
frontl=rearl=-1;
else
frontl++;
return;
}
printf("Deleted Element from High PQ is %d\n",hpq[fronth]);
if(fronth==rearh)
fronth=rearh=-1;
else
fronth++;
return;
}
void display()
{
if(fronth==-1 && frontl==-1)
{
printf("\nHPQ Empty\n");
printf("LPQ Empty\n");
return;
}
else if(fronth==-1 && frontl!=-1)
{
printf("\nHPQ Empty\n");
printf("\nLPQ Elements are:-\n");
for(int i=frontl;i<=rearl;i++)
printf("%d\t",lpq[i]);
return;
}
else if(fronth!=-1 && frontl==-1)
{
printf("\nHPQ Elements are:-\n");
for(int i=fronth;i<=rearh;i++)
printf("%d\t",hpq[i]);
printf("\nLPQ Empty\n");
return;
}
else
{
printf("\nHPQ Elements are:-\n");
for(int i=fronth;i<=rearh;i++)
printf("%d\t",hpq[i]);
printf("\nLPQ Elements are:-\n");
for(int i=frontl;i<=rearl;i++)
printf("%d\t",lpq[i]);
return;
}
}
void main()
{
int ch,elem,p;
printf("\nEnter HPQ Size: ");
scanf("%d",&sizeh);
printf("\nEnter LPQ Size: ");
scanf("%d",&sizel);
do
{
printf("\n\t\t**MENU**\t\t\n");
printf("1.Insert\n2.Delete\n3.Display\n4.Exit\n");
printf("Enter Your Choice :");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter Data: ");
scanf("%d",&elem);
printf("\nEnter Priority (1-High/0-Low):");
scanf("%d",&p);
if(p==1)
insert(hpq,&fronth,&rearh,&sizeh,elem);
else if(p==0)
insert(lpq,&frontl,&rearl,&sizel,elem);
else
printf("\nInvalid Choice!\n");
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\nInvalid Choice!\n");
}
}while(ch!=4);
}