1 | <?php |
||
23 | class ArrayList implements ListInterface { |
||
24 | use ArrayAccessTrait; |
||
25 | |||
26 | private $data; |
||
27 | private $current; |
||
28 | private $position; |
||
29 | private $size; |
||
30 | |||
31 | public function __construct() { |
||
36 | |||
37 | /** |
||
38 | * Add a new node in the specified index. |
||
39 | * |
||
40 | * @param integer $index the position. |
||
41 | * @param mixed $data the data to be stored. |
||
42 | */ |
||
43 | public function insert($index, $data) { |
||
47 | |||
48 | /** |
||
49 | * Removes all the array items. |
||
50 | */ |
||
51 | public function clear() { |
||
55 | |||
56 | /** |
||
57 | * Returns the array in the especified index. |
||
58 | * |
||
59 | * @param integer $index Index that must be greater than 0 |
||
60 | * and lower than the list size. |
||
61 | * @return mixed The data stored in the given index |
||
62 | * @throws OutOfBoundsException if index is out bounds. |
||
63 | */ |
||
64 | public function get($index) { |
||
71 | |||
72 | /** |
||
73 | * Returns the last node with O(1). |
||
74 | * |
||
75 | * @return mixed null if the array is empty. |
||
76 | */ |
||
77 | public function getLast() { |
||
84 | |||
85 | public function getAll() { |
||
90 | |||
91 | /** |
||
92 | * Removes and returns the last item in the array. |
||
93 | * |
||
94 | * @return mixed data in node. |
||
95 | */ |
||
96 | public function pop() { |
||
99 | |||
100 | /** |
||
101 | * Adds at the end of the list new node containing |
||
102 | * the data to be stored. |
||
103 | * |
||
104 | * @param mixed $data The data |
||
105 | */ |
||
106 | public function push($data) { |
||
110 | |||
111 | /** |
||
112 | * |
||
113 | */ |
||
114 | public function contains($data) : bool { |
||
117 | |||
118 | /** |
||
119 | * |
||
120 | */ |
||
121 | public function indexOf($data) { |
||
124 | |||
125 | /** |
||
126 | * |
||
127 | */ |
||
128 | public function lastIndexOf($data) { |
||
137 | |||
138 | /** |
||
139 | * |
||
140 | */ |
||
141 | public function remove($data) { |
||
157 | |||
158 | /** |
||
159 | * Adds at the beginning a node in the list. |
||
160 | * |
||
161 | * @param mixed $data |
||
162 | * @return mixed the data stored. |
||
163 | */ |
||
164 | public function unshift($data) { |
||
167 | |||
168 | /** |
||
169 | * Delete a node in the given position and returns it back. |
||
170 | * |
||
171 | * @param integer $index the position. |
||
172 | * @throws OutOfBoundsException if index is negative |
||
173 | * or is greater than the size of the list. |
||
174 | */ |
||
175 | public function delete($index) { |
||
186 | |||
187 | /** |
||
188 | * Deletes the first node of the list and returns it. |
||
189 | * |
||
190 | * @return mixed the data. |
||
191 | */ |
||
192 | public function shift() { |
||
195 | |||
196 | /** |
||
197 | * Returns array stored in the data attribute. |
||
198 | * |
||
199 | * @return array data stored in all nodes. |
||
200 | */ |
||
201 | public function toArray() : array { |
||
204 | |||
205 | /** |
||
206 | * Reset the cursor position. |
||
207 | */ |
||
208 | public function rewind() { |
||
212 | |||
213 | /** |
||
214 | * Returns the current node data. |
||
215 | * |
||
216 | * @return mixed |
||
217 | */ |
||
218 | public function current() { |
||
221 | |||
222 | /** |
||
223 | * Key or index that indicates the cursor position. |
||
224 | * |
||
225 | * @return integer The current position. |
||
226 | */ |
||
227 | public function key() { |
||
230 | |||
231 | /** |
||
232 | * Move the cursor to the next node and increments the |
||
233 | * position counter. |
||
234 | */ |
||
235 | public function next() { |
||
239 | |||
240 | /** |
||
241 | * Returns if the current pointer position is valid. |
||
242 | * |
||
243 | * @return boolean true if pointer is not last, else false. |
||
244 | */ |
||
245 | public function valid() { |
||
248 | |||
249 | /** |
||
250 | * Binds to count() method. This is equal to make $this->tree->size(). |
||
251 | * |
||
252 | * @return integer the tree size. 0 if it is empty. |
||
253 | */ |
||
254 | public function count() { |
||
257 | |||
258 | /** |
||
259 | * Returns the array size. |
||
260 | * |
||
261 | * @return int the length |
||
262 | */ |
||
263 | public function size() : int { |
||
266 | |||
267 | /** |
||
268 | * Checks if the list is empty. |
||
269 | * |
||
270 | * @return boolean true if is empty, else false. |
||
271 | */ |
||
272 | public function empty() : bool { |
||
275 | } |