-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQUEUE.c
152 lines (130 loc) · 3.12 KB
/
QUEUE.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include<stdio.h>
int queue[100],option,n,f=0,r=-1;
void Enqueue();
void Dequeue();
void peek();
void display();
void main()
{
printf("Enter the size of the queue (max size : 100) : ");
scanf("%d",&n);
printf("\n1)Enqueue\n2)Dequeue\n4)peek\n4)display()\n5)exit\n : ");
do{
printf("\nEnter the operation u want to perform : ");
scanf("%d",&option);
switch(option)
{
case 1 :
Enqueue();
break;
case 2:
Dequeue();
break;
case 3:
peek();
break;
case 4 :
display();
break;
case 5 :
break;
default :
break;
}
}while(option!=5);
}
void Enqueue()
{
if(r>=n-1)
{
printf("Overflow \n");
}
else
{
r=r+1;
printf("Enter the element u want to enqueu : ");
scanf("%d",&queue[r]);
}
}
void Dequeue()
{
if(f==r)
{
printf("%d is deleted ",queue[f]);
f=0;
r=-1;
}
else if(f>r)
{
printf("underflow \n");
}
else
{
printf( "%d is deleted ",queue[f] );
f=f+1;
}
}
void peek()
{
if(f>r)
{
printf("epmty \n");
}
else
{
printf("foremost element is %d : ",queue[f]);
}
}
void display()
{
if(f>r)
{
printf("epmty \n");
}
else
{
for(int i=f;i<=r;i++)
{
printf("%d\t",queue[i]);
}
}
}
/*******************************************************************
OUTPUT
Enter the size of the queue (max size : 100) : 3
1)Enqueue
2)Dequeue
4)peek
4)display()
5)exit
:
Enter the operation u want to perform : 1
Enter the element u want to enqueu : 2
Enter the operation u want to perform : 1
Enter the element u want to enqueu : 3
Enter the operation u want to perform : 1
Enter the element u want to enqueu : 4
Enter the operation u want to perform : 1
Overflow
Enter the operation u want to perform : 2
2 is deleted
Enter the operation u want to perform : 2
3 is deleted
Enter the operation u want to perform : 2
4 is deleted
Enter the operation u want to perform : 2
underflow
Enter the operation u want to perform : 1
Enter the element u want to enqueu : 5
Enter the operation u want to perform : 1
Enter the element u want to enqueu : 6
Enter the operation u want to perform : 2
5 is deleted
Enter the operation u want to perform : 1
Enter the element u want to enqueu : 7
Enter the operation u want to perform : 3
foremost element is 6 :
Enter the operation u want to perform : 4
6 7
Enter the operation u want to perform : 5
*******************************************************************/