-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueue_using_array.c
112 lines (105 loc) · 1.42 KB
/
queue_using_array.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
int SIZE;
int front,rear=-1;
int *a;
void createqueue(int s)
{
SIZE=s;
a=malloc(sizeof(SIZE));
}
bool isEmpty()
{
if (front==-1)
return true;
else
return false;
}
bool isFull()
{
if(rear==SIZE)
return true;
else
return false;
}
void enqueue(int item)
{
if(isFull())
printf("queue overflow");
else
{
a[++rear]=item;
printf("%d is inserted\n",item);
}
}
int dequeue()
{
if(isEmpty())
return 0;
else
return a[front++];
}
void display()
{
int i;
for(i=front;i<=rear;i++)
{
printf("%d \t",a[i]);
}
}
void main()
{
int s;
printf("Enter size of queue: ");
scanf("%d",&s);
createqueue(s);
while(1)
{
printf("\nMENU\n1.Enqueue\n2.Dequeue\n3.Is Empty?\n4.Is Full?\n5.Display\n");
printf("enter your choice: ");
int ch,item;
bool k;
scanf("%d",&ch);
switch(ch)
{
case 1:
//enqueue
printf("enter value to be inserted: ");
scanf("%d",&item);
enqueue(item);
break;
case 2:
//dequeue
item=dequeue();
if(item==0)
printf("queue underflow\n");
else
printf("%d deleted\n", item);
break;
case 3:
//isEmpty
k=isEmpty();
if(k==true)
printf("queue is empty");
else
printf("queue not empty");
break;
case 4:
//isFull
k=isFull();
if(k==true)
printf("queue overflow");
else
printf("queue not full");
break;
case 5:
//Display
display();
break;
default:
printf("Invalid choice\n");
exit(0);
}
}
}