-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_Array.cpp
More file actions
75 lines (67 loc) · 1.18 KB
/
Stack_Array.cpp
File metadata and controls
75 lines (67 loc) · 1.18 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
75
#include<bits/stdc++.h>
using namespace std;
#define MAX 10
class STACK{
int arr[MAX],front,top;
public:
STACK(){
top = -1;
}
int push(int val){
if (top >= MAX-1)
{
cout<<"OVERFLOW"<<endl;
return 0;
}
else{
arr[++top] = val;
return val;
}
}
int pop(){
if (top == -1)
{
cout<<"UNDERFLOW"<<endl;
return 0;
}
else{
top--;
}
}
int peek(){
if (top == -1) {
cout<<"UNDERFLOW"<<endl;
return 0;
}
else{
return arr[top];
}
}
void display(){
cout<<"----------STACK---------"<<endl;
if (top == -1)
{
/* code */
cout<<"UNDERFLOW"<<endl;
return;
}
for (int i = 0; i <= top; i++)
{
/* code */
cout<<arr[i]<<endl;
}
}
};
int main(){
STACK st;
st.push(5);
st.push(7);
st.push(9);
st.push(0);
st.push(1);
st.display();
st.pop();
st.pop();
st.pop();
st.display();
}