| @@ 278-294 (lines=17) @@ | ||
| 275 | * |
|
| 276 | * @return null if the head is null (or list is empty) |
|
| 277 | */ |
|
| 278 | public function getAll() { |
|
| 279 | if($this->head === null) { |
|
| 280 | return; |
|
| 281 | } |
|
| 282 | ||
| 283 | if($this->head->next === $this->tail) { |
|
| 284 | yield $this->head->data; |
|
| 285 | } else { |
|
| 286 | $current = $this->head; |
|
| 287 | $i = 0; |
|
| 288 | while($i < $this->size) { |
|
| 289 | yield $current->data; |
|
| 290 | $current = $current->next; |
|
| 291 | $i++; |
|
| 292 | } |
|
| 293 | } |
|
| 294 | } |
|
| 295 | ||
| 296 | /** |
|
| 297 | * Delete a node in the given position and returns it back. |
|
| @@ 202-218 (lines=17) @@ | ||
| 199 | * |
|
| 200 | * @return null if the head is null (or list is empty) |
|
| 201 | */ |
|
| 202 | public function getAll() { |
|
| 203 | if($this->head === null) { |
|
| 204 | return; |
|
| 205 | } |
|
| 206 | ||
| 207 | if($this->head === $this->tail) { |
|
| 208 | yield $this->head->data; |
|
| 209 | } else { |
|
| 210 | $current = $this->head; |
|
| 211 | $i = 0; |
|
| 212 | while($i < $this->size) { |
|
| 213 | yield $current->data; |
|
| 214 | $current = $current->next; |
|
| 215 | $i++; |
|
| 216 | } |
|
| 217 | } |
|
| 218 | } |
|
| 219 | ||
| 220 | /** |
|
| 221 | * Inserts data in the specified position. |
|