@@ 234-250 (lines=17) @@ | ||
231 | * |
|
232 | * @return null if the head is null (or list is empty) |
|
233 | */ |
|
234 | public function getAll() { |
|
235 | if($this->head === null) { |
|
236 | return; |
|
237 | } |
|
238 | ||
239 | if($this->head === $this->tail) { |
|
240 | yield $this->head->data; |
|
241 | } else { |
|
242 | $current = $this->head; |
|
243 | $i = 0; |
|
244 | while($i < $this->size) { |
|
245 | yield $current->data; |
|
246 | $current = $current->next; |
|
247 | $i++; |
|
248 | } |
|
249 | } |
|
250 | } |
|
251 | ||
252 | /** |
|
253 | * Inserts at the beginning of the list. |
@@ 274-290 (lines=17) @@ | ||
271 | * |
|
272 | * @return null if the head is null (or list is empty) |
|
273 | */ |
|
274 | public function getAll() { |
|
275 | if($this->head === null) { |
|
276 | return; |
|
277 | } |
|
278 | ||
279 | if($this->head->next === $this->tail) { |
|
280 | yield $this->head->data; |
|
281 | } else { |
|
282 | $current = $this->head; |
|
283 | $i = 0; |
|
284 | while($i < $this->size) { |
|
285 | yield $current->data; |
|
286 | $current = $current->next; |
|
287 | $i++; |
|
288 | } |
|
289 | } |
|
290 | } |
|
291 | ||
292 | /** |
|
293 | * Delete a node in the given position and returns it back. |