-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_array.cpp
More file actions
61 lines (51 loc) · 1.01 KB
/
stack_array.cpp
File metadata and controls
61 lines (51 loc) · 1.01 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
#include <bits/stdc++.h>
using namespace std;
struct Stack{ // array
private:
int stack[100], size = 100, top = -1;
public:
void push(int val){
if(isFull()){
cout << "OVERFLOW, the stack is full" << endl;
return;
}
else{
stack[++top] = val;
}
}
int pop(){
if(isEmpty()){
cout << "UNDERFLOW, the stack is empty" << endl;
return -1;
}
else{
return stack[top--];
}
}
int get_top(){
if(isEmpty()){
cout << "UNDERFLOW, the stack is empty" << endl;
return -1;
}
else{
return stack[top];
}
}
bool isFull(){
return (top == size - 1);
}
bool isEmpty(){
return (top == -1);
}
};
int main()
{
Stack st;
for(int i = 0; i < 100; i++){
st.push(i);
}
for(int i = 0; i < 100; i++){
cout << st.get_top() << endl;
st.pop();
}
}