Repository navigation
Expand file tree
/
Copy pathqueueArray.c
More file actions
98 lines (91 loc) · 1.59 KB
/
Copy pathqueueArray.c
File metadata and controls
98 lines (91 loc) · 1.59 KB
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
/** implementation of queue in c using array */
#include <stdio.h>
int Queue[100];
int QueueSize = 0;
void enqueue()
{
if (QueueSize == 100)
{
printf("Queue is full");
}
else
{
int val;
printf("Enter the value to enqueue: ");
scanf("%d", &val);
Queue[QueueSize] = val;
QueueSize++;
}
}
void dequeue()
{
if (QueueSize == 0)
{
printf("Queue is empty");
}
else
{
int val = Queue[0];
for (int i = 0; i < QueueSize; i++)
{
Queue[i] = Queue[i + 1];
}
QueueSize--;
printf("Dequeued value is %d", val);
}
}
void isEmpty()
{
if (QueueSize == 0)
{
printf("Queue is empty");
}
else
{
printf("Queue is not empty");
}
}
void isFull()
{
if (QueueSize == 100)
{
printf("Queue is full");
}
else
{
printf("Queue is not full");
}
}
void main()
{
int choice;
printf("1. Enqueue\n2. Dequeue\n3. Is Empty\n4. Is Full\n5. Exit\n");
do
{
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
isEmpty();
break;
case 4:
isFull();
break;
case 5:
printf("Exiting...");
break;
default:
printf("Invalid choice");
break;
}
printf("\n");
} while (choice != 5);
return 0;
}