| @@ 316-332 (lines=17) @@ | ||
| 313 | * |
|
| 314 | * @return null if the head is null (or list is empty) |
|
| 315 | */ |
|
| 316 | public function getAll() { |
|
| 317 | if($this->head === null) { |
|
| 318 | return; |
|
| 319 | } |
|
| 320 | ||
| 321 | if($this->head->next === $this->tail) { |
|
| 322 | yield $this->head->data; |
|
| 323 | } else { |
|
| 324 | $current = $this->head; |
|
| 325 | $i = 0; |
|
| 326 | while($i < $this->size) { |
|
| 327 | yield $current->data; |
|
| 328 | $current = $current->next; |
|
| 329 | $i++; |
|
| 330 | } |
|
| 331 | } |
|
| 332 | } |
|
| 333 | ||
| 334 | /** |
|
| 335 | * Delete a node in the given position and returns it back. |
|
| @@ 235-251 (lines=17) @@ | ||
| 232 | * |
|
| 233 | * @return null if the head is null (or list is empty) |
|
| 234 | */ |
|
| 235 | public function getAll() { |
|
| 236 | if($this->head === null) { |
|
| 237 | return; |
|
| 238 | } |
|
| 239 | ||
| 240 | if($this->head === $this->tail) { |
|
| 241 | yield $this->head->data; |
|
| 242 | } else { |
|
| 243 | $current = $this->head; |
|
| 244 | $i = 0; |
|
| 245 | while($i < $this->size) { |
|
| 246 | yield $current->data; |
|
| 247 | $current = $current->next; |
|
| 248 | $i++; |
|
| 249 | } |
|
| 250 | } |
|
| 251 | } |
|
| 252 | ||
| 253 | /** |
|
| 254 | * Inserts data in the specified position. |
|