-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVecStack.h
More file actions
40 lines (33 loc) · 668 Bytes
/
VecStack.h
File metadata and controls
40 lines (33 loc) · 668 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
#ifndef STACK_VECSTACK_H
#define STACK_VECSTACK_H
#include <vector>
#include "Stack.h"
template <class T>
class VecStack: public Stack<T> {
public:
void push (const T& val);
T pop ();
bool empty();
private:
std::vector<T> stack;
int todelete = 0;
};
template<class T>
void
VecStack<T>::push(const T &val) {
stack.erase(stack.end()-todelete, stack.end());
todelete = 0;
stack.push_back(val);
}
template<class T>
T
VecStack<T>::pop() {
todelete++;
return *(stack.end()-todelete);
}
template<class T>
bool
VecStack<T>::empty() {
return (stack.size() == todelete);
}
#endif //STACK_VECSTACK_H