-
Notifications
You must be signed in to change notification settings - Fork 5
/
Queue.c
86 lines (78 loc) · 1.38 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
#include <stdio.h>
#define max 10
int arr[max], i, opt, front = -1, rear = -1;
void main()
{
while (1)
{
printf("1. Enqueue\n");
printf("2. Dequeue\n");
printf("3. Show\n");
printf("4. Exit\n\n");
printf("Enter your choice: ");
scanf("%d", &opt);
switch (opt)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
show();
break;
case 4:
exit(0);
break;
default:
printf("Enter a valid Choice");
break;
}
}
}
void enqueue()
{
int val;
if (rear == max - 1)
{
printf("The Queue is Full\n");
}
else
{
if (front == -1)
{
front = 0;
}
printf("Enter the value to insert: ");
scanf("%d", &val);
rear++;
arr[rear] = val;
}
}
void dequeue()
{
if (front == -1 || front > rear)
{
printf("Queue is Empty");
}
else
{
printf("Element deleteed from the Queue: %d\n", arr[front]);
front++;
}
}
void show()
{
if (front == -1 || front > rear)
{
printf("No Element is present\n");
}
else
{
for (i = front; i <= rear; i++)
{
printf("%d\n", arr[i]);
}
}
}