-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcq.c
84 lines (79 loc) · 2.38 KB
/
cq.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
#include<stdio.h>
void main()
{
int Q[10],R=-1,F=-1,i,n,ch,x,y;
printf("Enter size of array: ");
scanf("%d", &n);
for(i=0;i<10;i++)
Q[i]=0;
do
{
printf("\n1. Insert\n");
printf("2. Delete\n");
printf("3. Display\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1: if((R==n-1 && F==0)||(F==R+1))
{
printf("Queue Overflow!\n");
break;
}
if(R==n-1)
R=0;
else
{
printf("Enter elements:\n");
R++;
scanf("%d", &x);
Q[R]=x;
if(F==-1)
{
F=0;
}
}
break;
case 2: if(F==-1)
{
printf("Queue Underflow!\n");
}
else
{
y=Q[F];
printf("Deleted element is: %d\n", y);
if(F==R)
{
F=-1;
R=-1;
}
else if(F==n-1)
{
F=0;
}
else
F++;
}
break;
case 3: if(F==-1)
{
printf("Empty Queue!\n");
break;
}
else
{
printf("Display elements:\n");
for(i=F;i<=R;i++)
{
printf("%d \n",Q[i]);
}
}
break;
case 4:
printf("Exiting the program!\n");
break;
default: printf("Invalid choice!\n");
}
}while(ch!=4);
}