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