-
Notifications
You must be signed in to change notification settings - Fork 3
/
Queue_operation.c
80 lines (71 loc) · 2.3 KB
/
Queue_operation.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
//To implement queue in a 1D Array using Menu-Driven flow of control
//12.01.19
#include<stdio.h>
#include<process.h>
#include<conio.h>
main(){
int Queue[20];
int QueueRear,QueueFront,i,j,Answer;
QueueFront = QueueRear = -1;
//Continuous display of menu
while(1){
printf("\n Queue Using Array Operations Menu \n \n");
printf("1. Insert In Queue \n");
printf("2. Delete From Queue \n");
printf("3. Display Queue \n");
printf("4. Exit\n");
scanf("%d", &Answer);
switch (Answer)
{
case 1:
//Inserting in the queue
if(QueueRear == 19){
printf("Queue is full, Overflow\n");
}
else if(QueueFront == -1){
QueueFront++;
QueueRear++;
printf("Enter the value\n");
scanf("%d",&Queue[QueueRear]);
}
else{
QueueRear++;
printf("Enter the value\n");
scanf("%d",&Queue[QueueRear]);
}
break;
case 2:
//Deletion from the queue using FIFO
if(QueueFront == -1){
printf("Queue is empty, Underflow\n");
}
else if(QueueFront == QueueRear){
QueueFront = QueueRear = -1;
printf("Element deleted\n");
}
else{
QueueFront++;
printf("Element deleted\n");
}
break;
case 3:
//Display the queue
if(QueueFront == -1){
printf("Queue is empty, enter elements first \n");
}
else{
printf("Queue is \n");
for(i = QueueFront;i <= QueueRear;i++){
printf("%d \n", Queue[i]);
}
}
break;
default:
//Default to exit from the program
exit(0);
}
}
getch();
}
//Written in ANSI for the GNU-GCC compiler
//Elit Altum