-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cpp
More file actions
55 lines (46 loc) · 759 Bytes
/
Copy pathStack.cpp
File metadata and controls
55 lines (46 loc) · 759 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
#include <iostream>
using namespace std;
int top = -1;
void push(int arr[], int x, int n) {
if(top == n-1) {
cout<<"stack is full"<<endl;
}
else {
top = top + 1;
stack[top] = x;
}
}
void pop(int arr[], int n) {
if(isEmpty()) {
cout<<"Stack is empty"<<endl;
}
else {
top = top - 1;
}
}
int topElement() {
return stack[top];
}
bool isEmpty() {
if(top == -1)
return true;
else
return false;
}
int size() {
return top + 1;
}
int main() {
int stack[3];
push(stack, 5, 3);
push(stack, 15, 3);
push(stack, 10, 3);
cout<<"Stack size"<< size()<<endl;
push(stack, 20, 3);
for(int i=0; i<size(); i++) {
pop();
}
cout<<"Size of stack"<<size()<<endl;
pop();
cout<<size()<<endl;
}