-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNorQ.cpp
More file actions
74 lines (73 loc) · 1.33 KB
/
NorQ.cpp
File metadata and controls
74 lines (73 loc) · 1.33 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
// Implementation of Queue using array
#include <iostream>
#define Max 5
using namespace std;
class Queue
{
int rear, front;
int ar[Max];
public:
Queue()
{
front = -1;
rear = -1;
}
bool QEmpty();
int addQ(int e);
int delQ();
} q;
int Queue::addQ(int e)
{
if (rear >= Max - 1)
{
cout << "\nQueue full!";
}
else
{
ar[++rear] = e;
cout << e << " Added to Queue!" << endl;
}
}
bool Queue::QEmpty()
{
return (rear == front);
}
int Queue::delQ()
{
if (rear == front)
{
cout << "\nStack empty!";
}
else
{
int x = ar[++front];
return x;
}
}
int main()
{
int num, k;
do
{
cout << "Enter optio you wish to perform:0.Exit 1. To add element to queue 2. To retrieve element from queue\n";
cin >> k;
switch (k)
{
case 1:
cout << "Enter a number:" << endl;
cin >> num;
q.addQ(num);
break;
case 2:
cout << "The number removed is: " << q.delQ() << endl;
break;
default:
break;
}
} while (k != 0);
while (!q.QEmpty())
{
cout << "Removed " << q.delQ() << endl;
}
return 0;
}