-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path7_circqueue_array.cpp
More file actions
94 lines (86 loc) · 1.12 KB
/
7_circqueue_array.cpp
File metadata and controls
94 lines (86 loc) · 1.12 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
#include <iostream>
using namespace std;
#define n 10
void enqueue(int a[],int &r,int &f)
{
int v;
cin>>v;
if((r==n-1 && f==0) || (r==f-1))
{
cout<<"Overflow"<<endl;
}
else if(r==n-1 && f!=0)
{
r=0;
a[r]=v;
}
else if(r==-1 && f==-1)
{
r++;
a[r]=v;
f++;
}
else
{
r++;
a[r]=v;
}
}
void dequeue(int a[],int &r,int &f)
{
if(r==-1 && f==-1)
{
cout<<"Underflow"<<endl;
}
else if(f==r)
{
f=-1;
r=-1;
}
else if(f==n-1 && f!=r)
{
f=0;
}
else
{
f++;
}
}
void display(int a[], int r, int f)
{
int temp=f;
while(temp!=r)
{
cout<<a[temp++]<<" ";
if(temp==n && r!=n-1)
temp=0;
}
cout<<a[temp];
cout<<endl;
}
int main()
{
int a[n];
int r=-1,f=-1;
cout<<"Enter 'a' for insertion, 'b' for deletion, 'c' to display & 'x' to exit the menu"<<endl;
char ch;
cin>>ch;
while(ch!='x')
{
switch(ch)
{
case 'a':
enqueue(a,r,f);
break;
case 'b':
dequeue(a,r,f);
break;
case 'c':
display(a,r,f);
break;
}
cout<<"Enter your choice"<<endl;
cin>>ch;
}
return 0;
}