-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQueue_using_Array.c
87 lines (80 loc) · 1.18 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
// Operatins on Queue using array
#include<stdio.h>
#include<stdlib.h>
#define MAX 5
void enqueue(int);
void dqueue(int*);
void display();
struct QUEUE
{
int s[MAX];
int r,f;
}stk;
void main()
{
int i,a;
stk.r=stk.f=-1;
while(1)
{
printf("\n 1.Enter");
printf("\n 2.Delete");
printf("\n 3.Display");
printf("\n 4.Exit");
printf("\n Enter your choice between 1 to 4: ");
scanf("%d",&i);
switch(i)
{
case 1: printf("Enter the item to push in queue\n");
scanf("%d",&a);
enqueue(a);break;
case 2: dqueue(&a);
if(a!=-999)
printf("%d is Deleted\n",a);
break;
case 3: display();break;
case 4: exit(0);
default:printf("Please enter a choice in between 1 to 5");
}
}
}
void enqueue(int a)
{
if(stk.r == MAX-1)
{
printf("Queue is full \n");
return;
}
else
{
stk.s[++stk.r]=a;
return;
}
}
void dqueue(int *a)
{
if(stk.f==stk.r)
{
stk.f=stk.r=-1;
printf("Queue is empty \n");
*a=-999;
return;
}
else
{
*a=stk.s[++stk.f];
return;
}
}
void display()
{
int i;
if(stk.f==stk.r)
{
stk.f=stk.r=-1;
printf("Queue is empty \n");
return;
}
for (i=stk.f+1;i<=stk.r;i++)
printf("%d",stk.s[i]);
printf("\n");return;
}