-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.c
83 lines (74 loc) · 1.49 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
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
int f = 0, r = -1, q[MAX], ele;
void insert_rear()
{
if (r == MAX - 1)
{
printf("Queue overflow\n");
return;
}
printf("Enter the element to insert:");
scanf("%d", &ele);
r++;
q[r] = ele;
return;
}
void delete_front()
{
if (f > r)
{
printf("Queue underflow\n");
return;
}
ele = q[f];
f++;
printf("Element deleted is %d\n", ele);
return;
}
void display()
{
if (f > r)
{
printf("Queue underflow\n");
}
printf("Elements of queue:\n");
for (int i = f; i <= r; i++)
{
printf("%d\t", q[i]);
}
printf("\n");
}
int main()
{
int choice;
do
{
printf("\n----- Queue Menu -----\n");
printf("1. Insert Rear\n");
printf("2. Delete Front\n");
printf("3. Display\n");
printf("4. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
insert_rear();
break;
case 2:
delete_front();
break;
case 3:
display();
break;
case 4:
printf("Exiting the program. Bye!\n");
break;
default:
printf("Invalid choice! Please enter a valid option.\n");
}
} while (choice != 4);
return 0;
}