-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_DEQUEUE_CIRCULAR.cpp
159 lines (150 loc) · 2.83 KB
/
4_DEQUEUE_CIRCULAR.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//DPHBFE application
//ring buffer dequeue enqueue
//input restricted Queue
#include<iostream>
#define N 5
using namespace std;
class dequeue
{
int q[N];
int front;
int rear;
int no;
public:
//-----------------------------------------------------------------
dequeue()
{
front=-1;
rear=-1;
}
//-----------------------------------------------------------------
void insert_rear()
{
if(front==(rear+1)%N)//imp
{
cout<<"\nDEqueue full!!\n";
return;
}
cout<<"Enter no : ";
cin>>no;
if(front == -1)
++front;
rear=(rear + 1)%N;
q[rear]=no;
}
//------------------------------------------------------------------
/* void insert_front()
{
if(front==(rear+1)%N)
{
cout<<"\nDEqueue full!!\n";
return;
}
cout<<"Enter no : ";
cin>>no;
if(front == -1)
++front;
front=(front + 1)%N;
q[front]=no;
}
*///------------------------------------------------------------------
void delete_front()
{
if(front==-1 && rear==-1)
{
cout<<"DEqueue Empty!!"<<endl;
return;
}
if(front==rear)
{
front=(front+1)%N;//imp
cout<<"\nNumber Deleted!!"<<endl;
cout<<"All Numbers deleted now";
front=-1;
rear=-1;
return;
}
front=(front+1)%N;
cout<<"\nNumber Deleted!!"<<endl;
}
//------------------------------------------------------------------
void delete_rear()
{
if(front==-1 && rear==-1)
{
cout<<"DEqueue Empty!!"<<endl;
return;
}
if(front==rear)//IMP
{
rear=(rear-1)%N;
cout<<"Number Deleted!!"<<endl;
cout<<"All Numbers deleted now";
front=-1;
rear=-1;
return;
}
rear=(rear-1)%N;
cout<<"Number Deleted!!"<<endl;
}
//------------------------------------------------------------------
void display()
{
if(front==-1 && rear==-1)
{
cout<<"DEqueue Empty!!"<<endl;
return;
}
/* if(front==rear)
{
cout<<"All Numbers deleted";
front=-1;
rear=-1;
return;
}
*/
int i;
for(i=front;i!=rear;i=(i+1)%N)
{
cout<<"Number : "<<q[i]<<endl;
}
cout<<"Number : "<<q[i]<<endl;
}
//------------------------------------------------------------------
};
main()
{
dequeue d;
int op=-1;
while(op!=0)
{
cout<<"\n\n1.Insert from rear";
// cout<<"\n2.Insert from front";
cout<<"\n3.Delete from front";
cout<<"\n4.Delete from rear";
cout<<"\n5.Display";
cout<<"\nEnter Choice : ";
cin>>op;
switch(op)
{
case 1:
d.insert_rear();
break;
case 2:
//d.insert_front();
break;
case 3:
d.delete_front();
break;
case 4:
d.delete_rear();
break;
case 5:
d.display();
break;
default:
op=0;
break;
}
}
}