-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueueusingarray.c
More file actions
105 lines (100 loc) · 1.32 KB
/
Copy pathqueueusingarray.c
File metadata and controls
105 lines (100 loc) · 1.32 KB
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
#include<stdio.h>
#define N 10
typedef struct queue
{
int a[N];
int front,rear;
}queue;
void enqueue(queue *q,int x)
{
if(q->rear==N-1)
{
printf("\nQueue Overflow");
}
else
{
q->rear++;
q->a[q->rear]=x;
}
}
int isempty(queue *q)
{
if(q->front==q->rear+1)
return 1;
else
return 0;
}
int dequeue(queue *q)
{
int x;
if(isempty(q))
return -1;
else
{
x=q->a[q->front];
q->front++;
return x;
}
}
void display(queue *q)
{
int i;
if(isempty(q))
{
printf("\nQueue is empty...");
}
else
{
for(i=q->front;i<=q->rear;i++)
{
printf("\n%d",q->a[i]);
}
}
}
int main()
{
int ch,x;
queue q;
q.front=0;
q.rear=-1;
while(1)
{
printf("\nMenu:\n1-ENQUEUE\n2-DEQUEUE\n3-DISPLAY\n4-EXIT\nEnter Choice=");
scanf("%d",&ch);
if(ch==4)
break;
switch(ch)
{
case 1:
{
printf("\nEnter element to be inserted=");
scanf("%d",&x);
enqueue(&q,x);
}
break;
case 2:
{
x=dequeue(&q);
if(x==-1)
{
printf("\nQueue Underflow...");
}
else
{
printf("\nDeleted Element=%d",x);
}
}
break;
case 3:
{
display(&q);
}
break;
default:
{
printf("\nInvalid Choice...");
}
}
}
return 0;
}