-
Notifications
You must be signed in to change notification settings - Fork 0
/
program6.c
54 lines (54 loc) · 1.17 KB
/
program6.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
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
char q[MAX];
int f=0,r=0;
void insert(){
char e;
if((r+1)%MAX==f){
printf("\nQueue Overflow\n");
return;
}
printf("\nEnter element to be inserted\n");
scanf("\n%c",&e);
r=(r+1)%MAX;
q[r]=e;
}
void delete(){
if(f==r){
printf("\nQueue Underflow\n");
return;
}
f=(f+1)%MAX;
printf("\nThe element being dequeued is %c\n",q[f]);
}
void display() {
if (f == r) {
printf("\nEmpty Queue\n");
return;
}
int i = f;
printf("\nThe elements of the queue are:\n");
while (i != r) {
i = (i + 1) % MAX;
printf("%c ", q[i]);
}
printf("%c", q[r]); // Print the last element
}
int main(){
int ch;
while(1){
printf("\nMENU\n1.Insert\n2.Delete\n3.Display\n4.Exit\n");
printf("\nEnter your choice\n");
scanf("%d",&ch);
switch(ch){
case 1: insert();
break;
case 2: delete();
break;
case 3: display();
break;
case 4: exit(0);
}
}
}