forked from sanjaysunil34/hacktober2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9-PriorityQueue.c
More file actions
55 lines (49 loc) · 844 Bytes
/
9-PriorityQueue.c
File metadata and controls
55 lines (49 loc) · 844 Bytes
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
#include<stdio.h>
typedef struct {
int a[10];
} Queue;
Queue q;
int front=0;
int rear=0;
void enqueue(int n) {
int t,te;
if(rear<9)
{
q.a[rear]=n;
t=rear;
while(q.a[t]<q.a[t-1] && t>front)
{
te=q.a[t];
q.a[t]=q.a[t-1];
q.a[t-1]=te;
t--;
}
rear++;
}
}
int dequeue() {
if(rear == front)
{
return -1;
}
else
{
front++;
return q.a[front-1];
}
}
int main() {
int q, choice, n;
scanf("%d", &q);
while(q--) {
scanf("%d", &choice);
switch(choice) {
case 1: scanf("%d",&n);
enqueue(n);
break;
case 2: printf("%d\n", dequeue());
break;
}
}
return 0;
}