forked from till-tomorrow/Data-Structures-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
51 lines (42 loc) · 612 Bytes
/
Copy pathstack.cpp
File metadata and controls
51 lines (42 loc) · 612 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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
template<class T>
class Stack {
public:
Stack();
void push(T x);
T pop();
bool isEmpty();
T peek();
private:
std::vector<T> v;
};
template <class T>
Stack<T>::Stack() {
}
template <class T>
bool Stack<T>::isEmpty() {
return v.empty();
}
template <class T>
void Stack<T>::push(T x) {
v.push_back(x);
}
template <class T>
T Stack<T>::pop() {
T val = v.back();
v.pop_back();
return val;
}
template <class T>
T Stack<T>::peek() {
return v.back();
}
int main() {
Stack<int> s;
s.push(4);
cout<<s.peek();
return 0;
}