-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolleg 2nd assignment.cpp
56 lines (49 loc) · 1.16 KB
/
colleg 2nd assignment.cpp
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
#include <iostream>
using namespace std;
class Stack {
int top = -1;
int stk[100];
int length = 100;
public:
void push(int val) {
if (top>=length-1) {
cout<<"Stack Overflow"<<endl;
}
else {
top++;
stk[top]=val;
}
};
void pop() {
if (top<0) {
cout<<"Stack Underfow"<<endl;
}
else {
cout<<stk[top]<<" was popped from stack!"<<endl;
top--;
}
}
void display() {
if (top>=0) {
cout<<"[ "<<stk[top]<<endl;
for (int i=top-1; i>=1; i--) {
cout<<" "<<stk[i]<<endl;
}
cout<<" "<<stk[0]<<" ]";
}
else {
cout<<"Stack is empty!";
}
}
};
int main() {
Stack myStack;
myStack.push(10);
myStack.push(15);
myStack.push(15);
myStack.push(17);
myStack.push(69);
myStack.pop();
myStack.display();
return 0;
}