-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
65 lines (60 loc) · 757 Bytes
/
Copy pathstack.cpp
File metadata and controls
65 lines (60 loc) · 757 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
#include<iostream>
#include<vector>
#include<cstdio>
#define sz 10010
using namespace std;
class stack{
public:
int a[sz],top;
stack(){
top=-1;
}
void push(int x){
++top;
if(top==10009)
{
cout<<"Stack overflow!"<<endl;
return;
}
a[top]=x;
}
int Top(){
if(top==-1){
cout<<"Stack Empty!"<<endl;
return -1;
}
return a[top];
}
int pop(){
if(top==-1){
cout<<"Underflow!"<<endl;
return -1;
}
return a[top--];
}
bool empty(){
return !(~top);
}
void printStack(){
int k=top;
while(k!=-1){
cout<<a[k--]<<" ";
}
}
};
int main(){
stack dp;
dp.push(2);
dp.push(0);
dp.push(34);
dp.push(45);
dp.push(56);
dp.printStack();
dp.pop();
dp.printStack();
dp.pop();
dp.printStack();
dp.empty()?cout<<"YES"<<endl:cout<<"NO"<<endl;
cout<<dp.Top();
return 0;
}