-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.hpp
More file actions
84 lines (63 loc) · 1.76 KB
/
stack.hpp
File metadata and controls
84 lines (63 loc) · 1.76 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
83
84
#ifndef __STACK_HPP__
# define __STACK_HPP__
#include "vector.hpp"
namespace ft
{
template <class T, class Cont = ft::vector<T> >
class stack
{
public:
typedef Cont container_type;
typedef typename Cont::value_type value_type;
typedef typename Cont::size_type size_type;
typedef typename Cont::reference reference;
typedef typename Cont::const_reference const_reference;
explicit stack (const container_type& ctnr = container_type()):_cont(ctnr) { }
stack(const stack ©):_cont(copy._cont) { }
stack& operator=(const stack ©) {
if (this != ©)
_cont = copy._cont;
return *this;
}
~stack() { }
bool empty() const {
return _cont.empty();
}
size_type size() const {
return _cont.size();
}
value_type& top() {
return _cont.back();
}
const value_type& top() const {
return _cont.back();
}
void push (const value_type& val) {
_cont.push_back(val);
}
void pop() {
_cont.pop_back();
}
friend bool operator== (const stack<T,Cont>& lhs, const stack<T,Cont>& rhs) {
return(lhs._cont == rhs._cont);
}
friend bool operator!= (const stack<T,Cont>& lhs, const stack<T,Cont>& rhs) {
return(lhs._cont != rhs._cont);
}
friend bool operator< (const stack<T,Cont>& lhs, const stack<T,Cont>& rhs) {
return(lhs._cont < rhs._cont);
}
friend bool operator<= (const stack<T,Cont>& lhs, const stack<T,Cont>& rhs) {
return(lhs._cont <= rhs._cont);
}
friend bool operator> (const stack<T,Cont>& lhs, const stack<T,Cont>& rhs) {
return(lhs._cont > rhs._cont);
}
friend bool operator>= (const stack<T, Cont>& lhs, const stack<T,Cont>& rhs) {
return(lhs._cont >= rhs._cont);
}
private:
container_type _cont;
};
}
#endif