-
Notifications
You must be signed in to change notification settings - Fork 3
/
Queue.cpp
74 lines (68 loc) · 988 Bytes
/
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
// Implement Queue Data Structure
#include<iostream>
void enqueue(int);
void dequeue();
void show();
int queue[10] = {0,0,0,0,0,0,0,0,0,0}, front, rear;
using namespace std;
int main()
{
int i;
do
{
cout << "\n[1] Enqueue";
cout << "\n[2] Dequeue";
cout << "\n[3] Show Queue";
cout << "\n[0] Exit\n";
cin >> i;
if(i == 1)
{
int item;
cout << "\nEnter New Value :\n";
cin >> item;
enqueue(item);
}
else if(i == 2)
{
dequeue();
}
else if(i == 3)
{
show();
}
}while(i != 0);
}
void enqueue(int i)
{
if((rear + 1) % 10 == front)
{
cout << "\n**Queue Full**";
}
else
{
queue[rear] = i;
rear = (rear + 1) % 10;
cout << "\n**Item Enqueued**";
}
}
void dequeue()
{
if(front == rear)
{
cout << "\n**Queue Empty**";
}
else
{
queue[front] = 0;
front = (front + 1) % 10;
cout << "\n**Item Dequeued**";
}
}
void show()
{
for(int i = 0; i < 10; i++)
{
cout << queue[i] << " ";
}
cout << "\nFront->" << front << ", Rear->" << rear;
}