1 | <?php |
||
23 | class ArrayList implements ListInterface { |
||
24 | use CountTrait; |
||
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 | public function empty() : bool { |
||
94 | |||
95 | /** |
||
96 | * Removes and returns the last item in the array. |
||
97 | * |
||
98 | * @return mixed data in node. |
||
99 | */ |
||
100 | public function pop() { |
||
103 | |||
104 | /** |
||
105 | * Adds at the end of the list new node containing |
||
106 | * the data to be stored. |
||
107 | * |
||
108 | * @param mixed $data The data |
||
109 | */ |
||
110 | public function push($data) { |
||
114 | |||
115 | /** |
||
116 | * Adds at the beginning a node in the list. |
||
117 | * |
||
118 | * @param mixed $data |
||
119 | * @return mixed the data stored. |
||
120 | */ |
||
121 | public function unshift($data) { |
||
124 | |||
125 | /** |
||
126 | * Delete a node in the given position and returns it back. |
||
127 | * |
||
128 | * @param integer $index the position. |
||
129 | * @throws OutOfBoundsException if index is negative |
||
130 | * or is greater than the size of the list. |
||
131 | */ |
||
132 | public function delete($index) { |
||
143 | |||
144 | /** |
||
145 | * Deletes the first node of the list and returns it. |
||
146 | * |
||
147 | * @return mixed the data. |
||
148 | */ |
||
149 | public function shift() { |
||
152 | |||
153 | /** |
||
154 | * Returns array stored in the data attribute. |
||
155 | * |
||
156 | * @return array data stored in all nodes. |
||
157 | */ |
||
158 | public function toArray() : array { |
||
161 | |||
162 | /** |
||
163 | * Reset the cursor position. |
||
164 | */ |
||
165 | public function rewind() { |
||
169 | |||
170 | /** |
||
171 | * Returns the current node data. |
||
172 | * |
||
173 | * @return mixed |
||
174 | */ |
||
175 | public function current() { |
||
178 | |||
179 | /** |
||
180 | * Key or index that indicates the cursor position. |
||
181 | * |
||
182 | * @return integer The current position. |
||
183 | */ |
||
184 | public function key() { |
||
187 | |||
188 | /** |
||
189 | * Move the cursor to the next node and increments the |
||
190 | * position counter. |
||
191 | */ |
||
192 | public function next() { |
||
196 | |||
197 | /** |
||
198 | * Returns if the current pointer position is valid. |
||
199 | * |
||
200 | * @return boolean true if pointer is not last, else false. |
||
201 | */ |
||
202 | public function valid() { |
||
205 | |||
206 | public function offsetSet($offset, $value) { |
||
217 | |||
218 | public function offsetExists($offset) { |
||
225 | |||
226 | public function offsetUnset($offset) { |
||
229 | |||
230 | public function offsetGet($offset) { |
||
233 | } |