-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproblem2.c
70 lines (65 loc) · 1.2 KB
/
problem2.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
#include <stdio.h>
#include <stdlib.h>
int Q[3];
int front = 0;
int rear = 0;
void insert() {
printf("1. Chocolate\n 2. Vanilla\n 3.Butter Scotch\n");
int data;
if (rear + 1 == 3) {
printf("Queue is full\n");
} else {
printf("Enter item number: ");
scanf("%d", &data);
Q[rear++] = data;
}
}
void delete () {
if (front == 0 && rear == 0) {
printf("Queue is empty\n");
} else if (Q[front] == Q[front + 1] && Q[front] == Q[front + 2]) {
front = rear = 0;
} else if (Q[front] == Q[front + 1]) {
front += 2;
} else {
front++;
}
}
void display() {
for (int j = front; j <= rear; j++) {
if (Q[j] == 1) {
printf("Chockolate\n");
} else if (Q[j] == 2) {
printf("Vanilla\n");
} else if (Q[j] == 3) {
printf("Butter Scoth\n");
}
}
}
int menu() {
int option;
printf("1.order\n");
printf("2.Serve\n");
printf("3.exit\n");
scanf("%d", &option);
return option;
}
int main() {
int option;
while (1) {
option = menu();
switch (option) {
case 1:
insert();
printf("Order table\n");
display();
break;
case 2:
delete ();
display();
break;
case 3:
exit(0);
}
}
}