-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_CIRCULAR_QUEUE.cpp
113 lines (97 loc) · 1.44 KB
/
2_CIRCULAR_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
103
104
105
106
107
108
109
110
111
112
113
//remember == in if
#include<iostream>
#include<conio.h>
#define N 5
using namespace std;
class osqueue
{
private:
int q[N];
int front , rear;
public:
osqueue()
{
front = -1;
rear = -1;
}
void insert()
{
int n;
if(front==(rear+1)%N) //IMP
{
cout<<"queue full";
return;
}
else
{
cout<<"enter the no : ";
cin>>n;
if(front==-1)
{
++front;
}
rear=(rear+1)%N;
q[rear]=n;
}
}
void delete_()
{
if(rear==-1&&front==-1)
{
cout<<"queue is empty";
return;
}
if(front==rear)
{
front=-1;
rear=-1;
cout<<"Queue empty!!";
return;
}
front=(front+1)%N;
cout<<"No. Deleted"<<endl;
}
void display()
{
int i,j;
if(rear==-1 || front==-1)
{
cout<<"queue is empty";
return;
}
for(i=front;i!=rear;i=(i+1)%N)
{
cout<<"no is : "<<q[i]<<endl;
}
cout<<"no is : "<<q[i];
}
};
main()
{
osqueue q1;
int op=-1;
while(op!=0)
{
cout<<"\n\n1.INSERT";
cout<<"\n2.DELETE";
cout<<"\n3.DISPLAY";
cout<<"\n4.EXIT";
cout<<"\n\nenter choice ";
cin>>op;
switch(op)
{
case 1:
q1.insert();
break;
case 2:
q1.delete_();
break;
case 3:
q1.display();
break;
case 4:
op=0;
break;
}
}
}