-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.h
More file actions
82 lines (68 loc) · 2.36 KB
/
Copy pathstack.h
File metadata and controls
82 lines (68 loc) · 2.36 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef _STACK_H_
#define _STACK_H_
#include "deque.h"
namespace mmm {
// class of stack
template <class T, class Container = mmm::deque<T>> class stack {
public:
typedef typename Container::value_type value_type;
typedef typename Container::reference reference;
typedef typename Container::size_type size_type;
typedef typename Container::const_reference const_reference;
typedef Container container_type;
private:
container_type container_;
public:
stack() { }
explicit stack(const container_type &ctnr)
: container_(ctnr) {}
bool empty() const { return container_.empty(); }
size_type size() const { return container_.size(); }
reference top() { return (container_.back()); }
const_reference top() const { return (container_.back()); }
void push(const value_type &val) { container_.push_back(val); }
void pop() { container_.pop_back(); }
void swap(stack &other) { mmm::swap(container_, other.container_); }
template <typename T1, typename Container1>
friend bool operator==(const stack<T1, Container1> &,
const stack<T1, Container1> &);
template <typename T1, typename Container1>
friend bool operator<(const stack<T1, Container1> &,
const stack<T1, Container1> &);
};
template <class T, class Container>
bool operator==(const stack<T, Container> &x,
const stack<T, Container> &y) {
return x.container_ == y.container_;
}
template <class T, class Container>
bool operator!=(const stack<T, Container> &x,
const stack<T, Container> &y) {
return !(x == y);
}
template <typename T, typename Container>
inline bool operator<(const stack<T, Container> &x,
const stack<T, Container> &y) {
return x.c < y.c;
}
template <typename T, typename Container>
inline bool operator>(const stack<T, Container> &x,
const stack<T, Container> &y) {
return y < x;
}
template <typename T, typename Container>
inline bool operator<=(const stack<T, Container> &x,
const stack<T, Container> &y) {
return !(y < x);
}
template <typename T, typename Container>
inline bool operator>=(const stack<T, Container> &x,
const stack<T, Container> &y) {
return !(x < y);
}
template <class T, class Container>
void swap(stack<T, Container> &x, stack<T, Container> &y) {
x.swap(y);
}
} // namespace mmm
#endif