| @@ 246-262 (lines=17) @@ | ||
| 243 | * |
|
| 244 | * @return null if the head is null (or list is empty) |
|
| 245 | */ |
|
| 246 | public function getAll() { |
|
| 247 | if($this->head === null) { |
|
| 248 | return; |
|
| 249 | } |
|
| 250 | ||
| 251 | if($this->head->next === $this->tail) { |
|
| 252 | yield $this->head->data; |
|
| 253 | } else { |
|
| 254 | $current = $this->head; |
|
| 255 | $i = 0; |
|
| 256 | while($i < $this->size) { |
|
| 257 | yield $current->data; |
|
| 258 | $current = $current->next; |
|
| 259 | $i++; |
|
| 260 | } |
|
| 261 | } |
|
| 262 | } |
|
| 263 | ||
| 264 | /** |
|
| 265 | * Delete a node in the given position and returns it back. |
|
| @@ 154-170 (lines=17) @@ | ||
| 151 | * |
|
| 152 | * @return null if the head is null (or list is empty) |
|
| 153 | */ |
|
| 154 | public function getAll() { |
|
| 155 | if($this->head === null) { |
|
| 156 | return; |
|
| 157 | } |
|
| 158 | ||
| 159 | if($this->head === $this->tail) { |
|
| 160 | yield $this->head->data; |
|
| 161 | } else { |
|
| 162 | $current = $this->head; |
|
| 163 | $i = 0; |
|
| 164 | while($i < $this->size) { |
|
| 165 | yield $current->data; |
|
| 166 | $current = $current->next; |
|
| 167 | $i++; |
|
| 168 | } |
|
| 169 | } |
|
| 170 | } |
|
| 171 | ||
| 172 | /** |
|
| 173 | * Checks if the list is empty. |
|