forked from D3v3sh5ingh/C-Plus-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue Using Array.cpp
More file actions
78 lines (68 loc) · 807 Bytes
/
Queue Using Array.cpp
File metadata and controls
78 lines (68 loc) · 807 Bytes
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
#include<iostream>
using namespace std;
int queue[10];
int front=0;
int rear=0;
void Enque(int x)
{
if(rear==10)
{
cout<<"\nOverflow";
}
else
{
queue[rear++]=x;
}
}
void Deque()
{
if (front==rear)
{
cout<<"\nUnderflow";
}
else
{
cout<<"\n"<<queue[front++]<<" deleted";
for (int i = front; i < rear; i++)
{
queue[i-front]=queue[i];
}
rear=rear-front;
front=0;
}
}
void show()
{
for (int i = front; i < rear; i++)
{
cout<<queue[i]<<"\t";
}
}
int main()
{
int ch, x;
do
{
cout<<"\n1. Enque";
cout<<"\n2. Deque";
cout<<"\n3. Print";
cout<<"\nEnter Your Choice : ";
cin>>ch;
if (ch==1)
{
cout<<"\nInsert : ";
cin>>x;
Enque(x);
}
else if (ch==2)
{
Deque();
}
else if (ch==3)
{
show();
}
}
while(ch!=0);
return 0;
}