-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack_array.cpp
More file actions
49 lines (42 loc) · 751 Bytes
/
Stack_array.cpp
File metadata and controls
49 lines (42 loc) · 751 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
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;
class MyStack {
public:
vector<int> s_array;
int head = -1;
MyStack() {
}
void push(int x) {
s_array.push_back(x);
head++;
}
int pop() {
head--;
}
int top() {
return s_array[head];
}
bool empty() {
if(head == -1){
return true;
}
else{
return false;
}
}
};
int main(){
vector<int> nums = {-1,0,3,5,9,12};
int target = 9;
MyStack A;
//A.MyStack();
A.push(1);
A.push(2);
cout << A.top() << endl;
A.pop();
cout << A.empty() << endl;
cout << A.top() << endl;
return 0;
}