-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.h
63 lines (49 loc) · 1.24 KB
/
Stack.h
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
#ifndef STACK_H
#define STACK_H
#include"Deque.h"
template<typename T>
class Stack {
public:
typedef T value_type;
typedef Deque<T> container_type;
typedef T& reference;
typedef const T& const_reference;
typedef size_t size_type;
private:
container_type _deque;
public:
explicit Stack(const container_type &ctnr) :_deque(ctnr) {};
explicit Stack(container_type &&ctnr = container_type()) :_deque(ctnr) {};
template<typename Alloc>
explicit Stack(const Alloc &alloc) :_deque(alloc) {};
template<typename Alloc>
Stack(const container_type &ctnr, const Alloc &alloc) :_deque(ctnr, alloc) {};
template<typename Alloc>
Stack(const Stack &x, const Alloc &alloc) :_deque(x._deque, alloc) {};
bool empty() const {
return _deque.empty();
}
size_type size() const {
return _deque.size();
}
reference& top() {
return _deque.back();
}
const_reference& top() const {
return _deque.back();
}
void push(const value_type &val) {
_deque.push_back(val);
}
template<typename... Args>
void emplace(Args&&... args) {
_deque.emplace_back(args...);
}
void pop() {
_deque.pop_back();
}
void swap(Stack &x) {
_deque.swap(x._deque);
}
};
#endif // !STACK_H