-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArray_Queue.c
95 lines (91 loc) · 1.54 KB
/
Array_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
87
88
89
90
91
92
93
94
95
//Array Queue
# include <stdio.h>
# include <stdlib.h>
# define max 5
int front = 0, rare = 0,data,stack[max];
void Enqueue(void);
void Dequeue(void);
void Display(void);
int Full(void);
int Empty(void);
void initialize(void);
int main()
{
int ch;
while(1)
{
scanf("%d",&ch);
switch (ch) {
case 1:
Enqueue();
break;
case 2:Dequeue();
break;
case 3:Display();
break;
case 4:initialize();
break;
case 5:exit(1);
break;
default:printf("Invalid option\n");
break;
}
}
return 0;
}
int Full()
{
if(rare == max)
return 1;
else
return 0;
}
int Empty()
{
if(rare == front)
return 1;
else
return 0;
}
void Enqueue()
{
if(Full())
printf("Queue is Full\n");
else
{
printf("Enter Queue data\n");
scanf("%d",&data);
stack[rare] = data;
rare++;
}
}
void Dequeue()
{
if(Empty())
printf("queue is Empty\n");
else
{
printf("Data %d is Deleted\n",stack[front]);
for (int i=front;i<rare;i++)
{
stack[i] = stack[i+1];
}
rare--;
}
}
void Display()
{
if(Empty())
printf("Queue is Empty\n");
else
{
for (int i = 0 ; i<rare ; i++)
{
printf("%d ",stack[i]);
}
}
}
void initialize()
{
front = rare = 0;
}