-
Notifications
You must be signed in to change notification settings - Fork 0
/
queues.c
75 lines (65 loc) · 1.09 KB
/
queues.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
#include<stdio.h>
#define MAX 10
int queues[MAX];
int front,rear=-1;
void enqueue(int ele){
if(front==-1){
queues[++rear]=ele;
++front;
}
else if(rear==(MAX-1)){
printf("queue overflow\n");
}
else{
queues[++rear]=ele;
}
cc
}
int dequeue(){
int c=999;
if(front==-1 || front>rear){
printf("queue underflow\n");
}
else{
c=queues[front++];
}
printf("front is %d and rear is %d\n",front,rear);
return c;
}
void display(){
if(front==-1 || front>rear){
printf("queue is empty\n");
}
else{
for(int i=front;i<=rear;i++){
printf(" %d ",queues[i]);
}
printf("\n");
}
}
void main(){
while(1){
printf("Enter 1 to enqueue\n");
printf("Enter 2 to dequeue\n");
printf("Enter 3 to display\n");
printf("Enter 4 to exit\n");
int choice;
scanf("%d",&choice);
switch(choice){
case 1:
printf("Enter element:\n");
int ele;
scanf("%d",&ele);
enqueue(ele);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit(1);
}
}
}