This repository has been archived by the owner on Oct 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeque-template.hpp
186 lines (180 loc) · 4.04 KB
/
deque-template.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#ifndef SJTU_DEQUE_HPP
#define SJTU_DEQUE_HPP
#include "exceptions.hpp"
#include <cstddef>
namespace sjtu {
template<class T>
class deque {
public:
class const_iterator;
class iterator {
private:
/**
* TODO add data members
* just add whatever you want.
*/
public:
/**
* return a new iterator which pointer n-next elements
* even if there are not enough elements, the behaviour is **undefined**.
* as well as operator-
*/
iterator operator+(const int &n) const {
//TODO
}
iterator operator-(const int &n) const {
//TODO
}
// return th distance between two iterator,
// if these two iterators points to different vectors, throw invaild_iterator.
int operator-(const iterator &rhs) const {
//TODO
}
iterator operator+=(const int &n) {
//TODO
}
iterator operator-=(const int &n) {
//TODO
}
/**
* TODO iter++
*/
iterator operator++(int) {}
/**
* TODO ++iter
*/
iterator& operator++() {}
/**
* TODO iter--
*/
iterator operator--(int) {}
/**
* TODO --iter
*/
iterator& operator--() {}
/**
* TODO *it
*/
T& operator*() const {}
/**
* TODO it->field
*/
T* operator->() const noexcept {}
/**
* a operator to check whether two iterators are same (pointing to the same memory).
*/
bool operator==(const iterator &rhs) const {}
bool operator==(const const_iterator &rhs) const {}
/**
* some other operator for iterator.
*/
bool operator!=(const iterator &rhs) const {}
bool operator!=(const const_iterator &rhs) const {}
};
class const_iterator {
// it should has similar member method as iterator.
// and it should be able to construct from an iterator.
private:
// data members.
public:
const_iterator() {
// TODO
}
const_iterator(const const_iterator &other) {
// TODO
}
const_iterator(const iterator &other) {
// TODO
}
// And other methods in iterator.
// And other methods in iterator.
// And other methods in iterator.
};
/**
* TODO Constructors
*/
deque() {}
deque(const deque &other) {}
/**
* TODO Deconstructor
*/
~deque() {}
/**
* TODO assignment operator
*/
deque &operator=(const deque &other) {}
/**
* access specified element with bounds checking
* throw index_out_of_bound if out of bound.
*/
T & at(const size_t &pos) {}
const T & at(const size_t &pos) const {}
T & operator[](const size_t &pos) {}
const T & operator[](const size_t &pos) const {}
/**
* access the first element
* throw container_is_empty when the container is empty.
*/
const T & front() const {}
/**
* access the last element
* throw container_is_empty when the container is empty.
*/
const T & back() const {}
/**
* returns an iterator to the beginning.
*/
iterator begin() {}
const_iterator cbegin() const {}
/**
* returns an iterator to the end.
*/
iterator end() {}
const_iterator cend() const {}
/**
* checks whether the container is empty.
*/
bool empty() const {}
/**
* returns the number of elements
*/
size_t size() const {}
/**
* clears the contents
*/
void clear() {}
/**
* inserts elements at the specified locat on in the container.
* inserts value before pos
* returns an iterator pointing to the inserted value
* throw if the iterator is invalid or it point to a wrong place.
*/
iterator insert(iterator pos, const T &value) {}
/**
* removes specified element at pos.
* removes the element at pos.
* returns an iterator pointing to the following element, if pos pointing to the last element, end() will be returned.
* throw if the container is empty, the iterator is invalid or it points to a wrong place.
*/
iterator erase(iterator pos) {}
/**
* adds an element to the end
*/
void push_back(const T &value) {}
/**
* removes the last element
* throw when the container is empty.
*/
void pop_back() {}
/**
* inserts an element to the beginning.
*/
void push_front(const T &value) {}
/**
* removes the first element.
* throw when the container is empty.
*/
void pop_front() {}
};
}
#endif