-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.hpp
More file actions
45 lines (43 loc) · 1.59 KB
/
stack.hpp
File metadata and controls
45 lines (43 loc) · 1.59 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
#pragma once
#include "vector.hpp"
namespace ft {
template<
class T,
class Container = ft::vector<T>
>
class stack {
protected:
Container _container;
public:
typedef Container container_type;
typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type;
typedef typename Container::reference reference;
typedef typename Container::const_reference const_reference;
explicit stack(const container_type &ctnr = container_type()) : _container(ctnr) {}
size_type size() const { return _container.size(); }
bool empty() const { return _container.size() == 0; }
value_type &top() { return _container.back(); }
const value_type &top() const { return _container.back(); }
void push(const value_type &val) { _container.push_back(val); }
void pop() { _container.pop_back(); }
friend bool operator==(const stack &lhs, const stack &rhs) {
return lhs._container == rhs._container;
}
friend bool operator!=(const stack &lhs, const stack &rhs) {
return rhs._container != lhs._container;
}
friend bool operator<(const stack &lhs, const stack &rhs) {
return lhs._container < rhs._container;
}
friend bool operator>(const stack &lhs, const stack &rhs) {
return lhs._container > rhs._container;
}
friend bool operator<=(const stack &lhs, const stack &rhs) {
return lhs._container <= rhs._container;
}
friend bool operator>=(const stack &lhs, const stack &rhs) {
return lhs._container >= rhs._container;
}
};
}