-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.hpp
110 lines (95 loc) · 3.28 KB
/
stack.hpp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* stack.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dpoveda- <me@izenynn.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/11 09:59:50 by dpoveda- #+# #+# */
/* Updated: 2022/07/15 08:46:17 by dpoveda- ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef STACK_HPP_
# define STACK_HPP_
# include "vector.hpp"
namespace ft {
template<class T, class Container = ft::vector<T> >
class stack {
public:
// definitions
typedef Container container_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::size_type size_type;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
// constructors
explicit stack(const container_type& cntr = container_type())
: c(cntr) {}
stack(const stack& other)
: c(other.c) {}
// destructors
~stack(void) {}
// operator
stack& operator=(const stack& other) {
if (this != &other) {
this->c = other.c;
}
return *this;
}
// top
reference top(void) {
return this->c.back();
}
const_reference top(void) const {
return this->c.back();
}
// empty
bool empty(void) const {
return this->c.empty();
}
// size
size_type size(void) const {
return this->c.size();
}
// operations
void push(const value_type& value) {
this->c.push_back(value);
}
void pop(void) {
this->c.pop_back();
}
// operators
template< class T1, class C1 >
friend bool operator==(const stack<T1, C1> &lhs, const stack<T1, C1> &rhs);
template< class T1, class C1 >
friend bool operator<(const stack<T1, C1> &lhs, const stack<T1, C1> &rhs);
protected:
container_type c;
};
// operators
template< class T, class Container >
bool operator==( const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs ) {
return (lhs.c == rhs.c);
}
template< class T, class Container >
bool operator!=( const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs ) {
return !(lhs == rhs);
}
template< class T, class Container >
bool operator<( const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs ) {
return (lhs.c < rhs.c);
}
template< class T, class Container >
bool operator<=( const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs ) {
return !(rhs < lhs);
}
template< class T, class Container >
bool operator>( const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs ) {
return (rhs < lhs);
}
template< class T, class Container >
bool operator>=( const ft::stack<T,Container>& lhs, const ft::stack<T,Container>& rhs ) {
return !(lhs < rhs);
}
}
#endif