-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue_array.c
75 lines (68 loc) · 1.41 KB
/
Queue_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
#include<stdio.h>
#include<stdlib.h>
#define n 5
int queue[n],choice,front=0,rear=0,i,j=1,x=n;
void Enqueue()
{
if(rear==x)
printf("\n Queue is Full");
else
{
printf("\n Enter no %d:",j++);
scanf("%d",&queue[rear++]);
}
}
void Dequeue()
{
if(front==rear)
{
printf("\n Queue is empty");
}
else
{
printf("\n Deleted Element is %d",queue[front++]);
x++;
}
}
int Display()
{
printf("\nQueue Elements are:\n ");
if(front==rear)
printf("\n Queue is Empty");
else
{
for(i=front; i<rear; i++)
{
printf("%d",queue[i]);
printf("\n");
}
}
return 0;
}
int main()
{
printf("Queue using Array");
printf("\n1.Enqueue \n2.Dequeue \n3.Display \n4.Exit");
while(1)
{
printf("\nEnter the Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
Enqueue();
break;
case 2:
Dequeue();
break;
case 3:
Display();
break;
case 4:
exit(0);
default:
printf("Wrong Choice: please see the options");
}
}
return 0;
}