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