forked from iamAnki/CPP-Programs-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircularqueue.cpp
More file actions
113 lines (96 loc) · 1.94 KB
/
circularqueue.cpp
File metadata and controls
113 lines (96 loc) · 1.94 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
111
112
113
//this is program for circular-queue in C++ languauge
#include<iostream>
using namespace std;
int q[4];
int f=-1;
int r=-1;
void insert_element()
{
if(f==0 and r==3 or f==r+1)
{
cout<<"Queue overflow....!!"<<endl;
}
else
{
int ele;
cout<<"Enter the element : "<<endl;
cin>>ele;
r=(r+1)%4;
q[r]=ele;
cout<<"Element inserted in Queue sucessfully...."<<endl;
if(f==-1)
{
f=0;
}
}
}
void remove_element()
{
if(f==0 and r==-1)
{
cout<<"Queue underflow...."<<endl;
}
else
{
cout<<"Element "<<q[f]<<" removed sucessfuly..."<<endl;
f=(f+1)%4;
}
}
void display()
{
if(f==0 and r==-1)
{
cout<<"Queue is EMPTY..."<<endl;
}
else
{
if(f<=r)
{
int i=f;
while(i<=r)
{
cout<<q[i]<<" ";
i++;
}
}
else
{
for(int i=0;i<=r;i++)
{
cout<<q[i]<<endl;
}
for(int i=f;i<=3;i++)
{
cout<<q[i]<<endl;
}
}
}
}
int main()
{
int i;
do{
printf("\n\t\tCIRCULAR QUEUE OPERATIONS\n");
printf("\n****************MENU**********************\n");
printf("\n1-INSERT elements in queue:\n");
printf("2- REmOVE elements in queue:\n");
printf("3-DISPLAY elements in queue:\n");
printf("4-EXIT\n");
printf("Provide your choice :");
cin>>i;
switch(i)
{
case 1:
insert_element();
break;
case 2:
remove_element();
break;
case 3:
display();
break;
case 4:
exit(0);
}
}while(true);
}