-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.h
More file actions
51 lines (39 loc) · 655 Bytes
/
Copy pathstack.h
File metadata and controls
51 lines (39 loc) · 655 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
#ifndef __STACK_H__
#define __STACK_H__
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
template <typename T>
class Stack {
private:
std::vector<T> vec;
public:
Stack() : vec() {}
void push(const T& t) {
vec.push_back(t);
}
T pop() {
assert(vec.size() != 0);
T t = vec.back();
vec.pop_back();
return t;
}
//for debugging uses
void dump_data() {
for (const T& d : vec) {
std::cout << d << std::endl;
}
std::cout << std::endl;
}
bool is_empty() const {
return vec.size() == 0;
}
int size() const {
return vec.size();
}
T const& peek() const {
return vec.back();
}
};
#endif