-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path9_01_User_defined_stack.cpp
More file actions
67 lines (57 loc) · 1.39 KB
/
9_01_User_defined_stack.cpp
File metadata and controls
67 lines (57 loc) · 1.39 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
# include<bits/stdc++.h>
using namespace std;
class Stack{
private:
int capacity;
vector<int> v;
int li = -1;
public:
Stack(int cap){
this->capacity = cap;
v.resize(cap);
}
int size(){
return (this->li+1);
}
bool isFull(){
return (this->capacity-1==li);
// if(this->capacity-1==top)
// return true;
// return false;
}
bool isEmpty(){
return(this->li==-1);
}
void push(int value){
if(this->capacity-1==li)
return;
this->v[++li] = value;
}
int top(){
if(isEmpty()){
cout << "Stack is empty invalid demand\n";
return -1;
}
return this->v[li];
}
void pop(){
if(isEmpty()){
cout << "Stack is empty invalid demand\n";
}
this->li--;
}
};
int main(){
Stack* s = new Stack(100);
int n;
cin >> n;
for(int i=0; i<n; i++){
int value;
cin >> value;
s->push(value);
}
cout << s->size() << " is size \n";
cout << s->top() << " is the top \n";
s->pop();
cout << s->size() << " is size \n";
}