-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.c
More file actions
81 lines (80 loc) · 1.13 KB
/
Copy pathqueue.c
File metadata and controls
81 lines (80 loc) · 1.13 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
#include<stdio.h>
int n;
int queue[20];
int front =-1;
int rear=-1;
void enqueue(int a)
{
if(rear==n-1)
printf("Overflow\n");
else if(front==-1 && rear==-1)
{
front=rear=0;
queue[rear]=a;
}
else
{
rear++;
queue[rear]=a;
}
}
void dequeue()
{
if(front==-1 && rear==-1)
printf("Underflow\n");
else if(front==rear)
front=rear=-1;
else
{
printf("%d is deleted from the queue\n ",queue[front]);
front++;
}
}
void display()
{
if(front==-1 && rear==-1)
printf("The queue is empty\n ");
else
{
for(int i=front;i<(rear+1);i++)
{
printf("%d\t",queue[i]);
}
printf("\n");
}
}
void main()
{
int x=0,y;
printf("Enter the size of the queue :");
scanf("%d",&n);
while(x!=4)
{
printf("1.Enqueue\n");
printf("2.Dequeue\n");
printf("3.Display\n");
printf("4.Exit\n");
printf("Choose the operation to perform :");
scanf("%d",&x);
switch(x)
{
case 1:
printf("Enter the no: to be entered :");
scanf("%d",& y);
enqueue(y);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
printf("Code successfully executed");
break;
default:
printf("Invalid Choice\n");
break;
}
}
}