TheAlgorithms/C++
1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
circular_queue_using_array.cpp
1
#include <iostream>
2
using
std::cin;
3
using
std::cout;
4
5
int
queue
[10];
6
int
front = 0;
7
int
rear = 0;
8
int
count = 0;
9
10
void
Enque(
int
x) {
11
if
(count == 10) {
12
cout <<
"\nOverflow"
;
13
}
else
{
14
queue
[rear] = x;
15
rear = (rear + 1) % 10;
16
count++;
17
}
18
}
19
20
void
Deque() {
21
if
(front == rear) {
22
cout <<
"\nUnderflow"
;
23
}
24
25
else
{
26
cout <<
"\n"
<<
queue
[front] <<
" deleted"
;
27
front = (front + 1) % 10;
28
count--;
29
}
30
}
31
32
void
show() {
33
for
(
int
i = 0; i < count; i++) {
34
cout <<
queue
[(i + front) % 10] <<
"\t"
;
35
}
36
}
37
38
int
main
() {
39
int
ch, x;
40
do
{
41
cout <<
"\n1. Enque"
;
42
cout <<
"\n2. Deque"
;
43
cout <<
"\n3. Print"
;
44
cout <<
"\nEnter Your Choice : "
;
45
cin >> ch;
46
if
(ch == 1) {
47
cout <<
"\nInsert : "
;
48
cin >> x;
49
Enque(x);
50
}
else
if
(ch == 2) {
51
Deque();
52
}
else
if
(ch == 3) {
53
show();
54
}
55
}
while
(ch != 0);
56
57
return
0;
58
}
queue
Definition
queue.hpp:9
main
int main()
Main function.
Definition
generate_parentheses.cpp:110
operations_on_datastructures
circular_queue_using_array.cpp
Generated by
1.12.0