-
Notifications
You must be signed in to change notification settings - Fork 0
/
queueArray.c
54 lines (48 loc) · 1.25 KB
/
queueArray.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
#include<stdio.h>
#include "queuearray.h"
/* Limitation:
(follow the operations)
enqueue (10)
enqueue (20)
enqueue (30)
dequeue
dequeue
dequeue
enqueue (40)
dequeue
... At this point both ... empty and full conditions both are satisfied... */
int main()
{
// declaring and initializing variables
Q queue;
int choice,toAppend,overflow,underflow,served;
initQueue(&queue); // function call to initialize the queue
do
{
printf("\n----------MENU-----------\n1.ENQUEUE\n2.DEQUEUE\n3.EXIT\nEnter choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\nEnter element to append: ");
scanf("%d",&toAppend);
append(&queue,toAppend,&overflow); // function call to append 'toAppend'
if(!overflow)
printf("\n%d appended successfully.\n",toAppend);
else
printf("\nQueue full.\n");
break;
case 2: serve(&queue,&served,&underflow); // function call to 'dequeue'
if(!underflow)
printf("\n%d served successfully.\n",served);
else
printf("\nQueue empty.\n");
break;
case 3: printf("\nDONE.\n");
break;
default: printf("\nRe-enter please...\n");
break;
}
}
while(choice!=3);
return 0;
}