-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp2.cpp
More file actions
44 lines (42 loc) · 1.17 KB
/
Copy pathp2.cpp
File metadata and controls
44 lines (42 loc) · 1.17 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
#include "ADTQueue.cpp"
#include<iomanip>
int main(){
int m; cin>>m;
Queue<int>q;
for(int i=1;i<=m;i++){
cout<<"["<<setw(2)<<i<<"]: ";
string opt; int x; cin>>opt;
if(opt=="enqueue") cin>>x;
bool ok; int t=-1;
if(opt=="clear"){
q.clear();
cout<<"CLEAR Q\n";
}else if(opt=="empty"){
cout<<"Q "<<(q.empty()?"is":"is't")<<" EMPTY\n";
}else if(opt=="length"){
cout<<"LENGTH OF Q: "<<q.length()<<"\n";
}else if(opt=="getHead"){
ok=q.getHead(t);
if(ok)
cout<<"Head OF Q: "<<t<<"\n";
else
cout<<"Q is empty, can't getHead!\n";
}else if(opt=="traverse"){
cout<<"Q: ";
q.traverse();
}else if(opt=="enqueue"){
q.push(x);
cout<<"ENQUEUE "<<x<<"\n";
}else if(opt=="dequeue"){
ok=q.pop(t);
if(ok)
cout<<"DEQUEUE "<<t<<"\n";
else
cout<<"Q is empty, can't pop!\n";
}else{
cerr<<"INVAILD INPUT!\n";
exit(-1);
}
}
return 0;
}