-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuee.c
90 lines (80 loc) · 1.2 KB
/
Quee.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
#include <stdio.h>
#include <stdlib.h>
void enqueue();
void dequeue();
void display();
int queue[100];
int Rear= -1;
int front =-1;
int n;
void main()
{
int O;
printf("Enter queue size: ");
scanf("%d",&n);
while (1)
{
printf("\n\nQueue Operations\n");
printf("1.Enqueue Operation\n");
printf("2.Dequeue Operation\n");
printf("3.Display the Queue \n");
printf("4.Exit\n");
printf("\n Enter your choice of operations: ");
scanf("%d",&O);
switch (O)
{
case 1:
enqueue();
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
exit (0);
default:
printf("incorrect choice\n");
}
}
}
void enqueue()
{
int item;
if (Rear==n-1)
printf("Overflow\n");
else
{
if (front == -1){
front=0;}
printf("Element to be inserted the Queue:");
scanf("%d",&item);
Rear=Rear+1;
queue[Rear]=item;
}
}
void dequeue()
{
if(front==-1 || front > Rear)
{
printf("Underflow\n");
}
else
{
printf("Element deleted from the Queue \n %d",queue[front]);
front=front+1;
}
}
void display()
{
if(front == -1)
printf("Empty Queue\n");
else
{
printf("Queue: ");
for(int i= front; i <= Rear; i++)
printf("%d ",queue[i]);
printf("\n");
}
}