-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.c
120 lines (101 loc) · 1.73 KB
/
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 5
struct lqueue {
int data[MAX];
int rear,front;
} q;
void initialize()
{
q.rear=q.front=-1;
}
int full()
{
if(q.rear==MAX-1)
return 1;
else
return 0;
}
int empty()
{
if((q.front==-1)||(q.front>q.rear))
return 1;
else
return 0;
}
void enqueue(int item)
{
int f;
f=full();
if(f!=1){
if (q.front == -1)
q.front=0;
q.rear=q.rear+1;
q.data[q.rear] = item;
}
else
printf("Queue Overflow");
}
void dequeue()
{
int no,e;
e=empty();
if(e!=1)
{
no=q.data[q.front];
if(q.front==q.rear)
q.front=q.rear=-1;
else
q.front= q.front+1;
printf("Deleted data is %d",no);
}
else
printf("\nQueue Underflow");
// return d;
}
void display()
{
int i;
if(q.front==-1)
printf("\nQueue Underflow");
else
{
printf("\nQueue is \n");
for(i=q.front;i<=q.rear;i++)
printf("%d\t",q.data[i]);
}
}
int main()
{
int choice,item;
char ans;
initialize();
printf("\n\tImplementation Of Queue");
do {
printf("\nMain Menu");
printf("\n1.Insertion \n2.Deletion \n3.Display \n4.exit");
printf("\nEnter Your Choice");
scanf("%d", &choice);
switch (choice) {
case 1:
{
printf("\nEnter The item to be inserted");
scanf("%d", &item);
enqueue(item);
}
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:printf("Default Case");
break;
}
printf("\nDo You want To Continue?");
ans = getche();
} while (ans == 'Y' || ans == 'y');
return 0;
}