-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCircularQueueArray.cpp
More file actions
115 lines (78 loc) · 1.26 KB
/
CircularQueueArray.cpp
File metadata and controls
115 lines (78 loc) · 1.26 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
106
107
108
109
110
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
const int max=1000;
int q[max];
int front=-1,rear=-1;
void insert();
void deletion();
void display();
int main()
{
char c;
while(1)
{
printf("Enter your choice :\n a.Insert \n b.Delete \n c.Display \n d.Exit \n");
scanf(" %c",&c);
switch(c)
{
case 'a' : insert();break;
case 'b' : deletion();break;
case 'c' : display();break;
case 'd' : exit(0);
default : printf("Invalid Input. Try again \n");
}
}
}
void insert()
{
int temp;
if(((rear==max-1)&&(front==0))||(front==rear+1))
{
printf("The queue is full(Overflow) \n");
return;
}
if(front!=0 && rear==(max-1))
rear=0;
printf("Enter the value to be inserted \n");
scanf("%d",&temp);
if(front==-1)
front=0;
q[++rear]=temp;
}
void deletion()
{
if(front==-1)
{
printf("List is empty(underflow)\n");
return;
}
printf("The value deleted is : %d \n",q[front]);
if(front==rear)
front=rear=-1;
else if(front==max-1)
front=0;
else front++;
}
void display()
{
int i=front;
if(front ==-1)
{
printf("The list is empty\n");
return;
}
if(front==rear)
{
printf("%d \n",q[front]);
return;
}
while(i!=rear)
{
printf("%d \n",q[i]);
i++;
if(i==max)
i=0;
}
printf("%d \n",q[i]);
}