forked from VinayBelwal/Hactober-22-Programs-and-Projects-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
queue.cpp
103 lines (84 loc) · 1.32 KB
/
queue.cpp
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
#include<stdio.h>
#include<stdlib.h>
#define max 50
int queue[max];
int front=-1;
int rear=-1;
void queue_insert(int);
void queue_delete();
void queue_display();
int main()
{
int choice,item;
while(1)
{
printf("\n 1: insert \n");
printf("\n 2: delete \n");
printf("\n 3: display \n");
printf("\n 4: exit \n");
printf("enter your choice \n");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("enter the element to be inserted \n");
scanf("%d",&item);
queue_insert(item);
break;
case 2: queue_delete();
break;
case 3: queue_display();
break;
case 4: exit(0);
break;
default : printf("incorrect choice\n");
}
}
}
void queue_insert(int item)
{
if(rear==max-1)
{
printf("queue is full");
return;
}
if(front==-1 && rear==-1)
{
front=rear=0;
}
else{
rear=rear+1;
}
queue[rear]=item;
}
void queue_delete()
{
int e;
if(front==-1 && rear==-1)
{
printf("queue empty \n");
return;
}
e=queue[front];
if(front==rear)
{
front=rear-1;
}
else{
front=front+1;
}
printf("the element deleted is =%d",e);
}
void queue_display()
{
int i;
if(front==-1 && rear==-1)
{
printf("queue empty \n");
return;
}
printf("the elements of queue are ");
for(i=front;i<=rear;i++)
{
printf("%d",queue[i]);
}
}