1 | <?php |
||
24 | class ArrayList extends ListAbstract { |
||
25 | use ArrayAccessTrait; |
||
26 | |||
27 | private $data; |
||
28 | private $current; |
||
29 | private $position; |
||
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 | * {@inheritDoc} |
||
113 | */ |
||
114 | public function contains($data) : bool { |
||
117 | |||
118 | /** |
||
119 | * {@inheritDoc} |
||
120 | */ |
||
121 | public function indexOf($data) { |
||
124 | |||
125 | /** |
||
126 | * {@inheritDoc} |
||
127 | */ |
||
128 | public function lastIndexOf($data) { |
||
137 | |||
138 | /** |
||
139 | * {@inheritDoc} |
||
140 | */ |
||
141 | public function remove($data) { |
||
155 | |||
156 | /** |
||
157 | * Adds at the beginning a node in the list. |
||
158 | * |
||
159 | * @param mixed $data |
||
160 | * @return mixed the data stored. |
||
161 | */ |
||
162 | public function unshift($data) { |
||
165 | |||
166 | /** |
||
167 | * Delete a node in the given position and returns it back. |
||
168 | * |
||
169 | * @param integer $index the position. |
||
170 | * @throws OutOfBoundsException if index is negative |
||
171 | * or is greater than the size of the list. |
||
172 | */ |
||
173 | public function delete($index) { |
||
184 | |||
185 | /** |
||
186 | * Deletes the first node of the list and returns it. |
||
187 | * |
||
188 | * @return mixed the data. |
||
189 | */ |
||
190 | public function shift() { |
||
193 | |||
194 | /** |
||
195 | * Returns array stored in the data attribute. |
||
196 | * |
||
197 | * @return array data stored in all nodes. |
||
198 | */ |
||
199 | public function toArray() : array { |
||
202 | |||
203 | /** |
||
204 | * Reset the cursor position. |
||
205 | */ |
||
206 | public function rewind() { |
||
210 | |||
211 | /** |
||
212 | * Returns the current node data. |
||
213 | * |
||
214 | * @return mixed |
||
215 | */ |
||
216 | public function current() { |
||
219 | |||
220 | /** |
||
221 | * Key or index that indicates the cursor position. |
||
222 | * |
||
223 | * @return integer The current position. |
||
224 | */ |
||
225 | public function key() { |
||
228 | |||
229 | /** |
||
230 | * Move the cursor to the next node and increments the |
||
231 | * position counter. |
||
232 | */ |
||
233 | public function next() { |
||
237 | |||
238 | /** |
||
239 | * Returns if the current pointer position is valid. |
||
240 | * |
||
241 | * @return boolean true if pointer is not last, else false. |
||
242 | */ |
||
243 | public function valid() { |
||
246 | } |