-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue_Using_Array.cpp.cpp
More file actions
74 lines (67 loc) · 1.33 KB
/
Copy pathQueue_Using_Array.cpp.cpp
File metadata and controls
74 lines (67 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
#include <iostream>
using namespace std;
const int Size=10;
int Queue[Size]={};
int Top=-1;
int Rear=-1;
void Enqueue(int val){
if(Rear==Size-1){cout<<"Overflow"<<endl;
return;}
else if(Top==-1 && Rear==-1){
Top=0;
Rear=0;}
else{Rear++;}
Queue[Rear]=val;
return;}\
void Dequeue(){
if(Top==-1 || Top>Rear){
cout<<"Underflow"<<endl;
return;}
else if(Top==Rear){Top=-1;
Rear=-1;
return;}
else{Top++;
return;}
}
void front(){
if(Top==-1|| Top>Rear){
cout<<"Underflow"<<endl;}
else{cout<<"The Front Value is:"<<Queue[Top]<<endl;}
}
void isEmpty(){
if(Top==-1 || Top>Rear){cout<<"True"<<endl;
return;}
else{cout<<"False"<<endl;
return;}}
void Display(){
if(Top==-1 || Top>Rear){cout<<"Queue Empty"<<endl;
return;}
else{
cout<<"The Queue is :"<<endl;
for(int i=Top;i<=Rear;i++){
cout<<Queue[i]<<' ';
}
cout<<endl;
}
}
int main(){
int n,x,val;
cout<<"Enter number of operations:"<<endl;
cin>>n;
for(int i=0;i<n;i++){
cout<<"1)Enqueue"<<endl;
cout<<"2)Dequeue"<<endl;
cout<<"3)Front"<<endl;
cout<<"4)isEmpty"<<endl;
cout<<"5)Display"<<endl;
cin>>x;
if(x==1){
cout<<"Enter Value to be added:"<<endl;
cin>>val;
Enqueue(val);}
else if(x==2){Dequeue();}
else if(x==3){front();}
else if(x==4){isEmpty();}
else {Display();}
}
}