-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.hpp
More file actions
190 lines (183 loc) · 4.91 KB
/
Copy pathvector.hpp
File metadata and controls
190 lines (183 loc) · 4.91 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
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
187
188
189
190
#ifndef SJTU_VECTOR_HPP
#define SJTU_VECTOR_HPP
#include "exceptions.hpp"
#include <climits>
#include <cstddef>
namespace sjtu {
/**
* a data container like std::vector
* store data in a successive memory and support random access.
*/
template<typename T>
class vector {
public:
/**
* TODO
* a type for actions of the elements of a vector, and you should write
* a class named const_iterator with same interfaces.
*/
/**
* you can see RandomAccessIterator at CppReference for help.
*/
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
* as well as operator-
*/
iterator operator+(const int &n) const {
//TODO
}
iterator operator-(const int &n) const {
//TODO
}
// return the distance between two iterators,
// if these two iterators point 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{}
/**
* a operator to check whether two iterators are same (pointing to the same memory address).
*/
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 {}
};
/**
* TODO
* has same function as iterator, just for a const object.
*/
class const_iterator {
};
/**
* TODO Constructs
* Atleast two: default constructor, copy constructor
*/
vector() {}
vector(const vector &other) {}
/**
* TODO Destructor
*/
~vector() {}
/**
* TODO Assignment operator
*/
vector &operator=(const vector &other) {}
/**
* assigns specified element with bounds checking
* throw index_out_of_bound if pos is not in [0, size)
*/
T & at(const size_t &pos) {}
const T & at(const size_t &pos) const {}
/**
* assigns specified element with bounds checking
* throw index_out_of_bound if pos is not in [0, size)
* !!! Pay attentions
* In STL this operator does not check the boundary but I want you to do.
*/
T & operator[](const size_t &pos) {}
const T & operator[](const size_t &pos) const {}
/**
* access the first element.
* throw container_is_empty if size == 0
*/
const T & front() const {}
/**
* access the last element.
* throw container_is_empty if size == 0
*/
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 value before pos
* returns an iterator pointing to the inserted value.
*/
iterator insert(iterator pos, const T &value) {}
/**
* inserts value at index ind.
* after inserting, this->at(ind) == value
* returns an iterator pointing to the inserted value.
* throw index_out_of_bound if ind > size (in this situation ind can be size because after inserting the size will increase 1.)
*/
iterator insert(const size_t &ind, const T &value) {}
/**
* removes the element at pos.
* return an iterator pointing to the following element.
* If the iterator pos refers the last element, the end() iterator is returned.
*/
iterator erase(iterator pos) {}
/**
* removes the element with index ind.
* return an iterator pointing to the following element.
* throw index_out_of_bound if ind >= size
*/
iterator erase(const size_t &ind) {}
/**
* adds an element to the end.
*/
void push_back(const T &value) {}
/**
* remove the last element from the end.
* throw container_is_empty if size() == 0
*/
void pop_back() {}
};
}
#endif