| @@ 227-243 (lines=17) @@ | ||
| 224 | * |
|
| 225 | * @return null if the head is null (or list is empty) |
|
| 226 | */ |
|
| 227 | public function getAll() { |
|
| 228 | if($this->head === null) { |
|
| 229 | return; |
|
| 230 | } |
|
| 231 | ||
| 232 | if($this->head->next === $this->tail) { |
|
| 233 | yield $this->head->data; |
|
| 234 | } else { |
|
| 235 | $current = $this->head; |
|
| 236 | $i = 0; |
|
| 237 | while($i < $this->size) { |
|
| 238 | yield $current->data; |
|
| 239 | $current = $current->next; |
|
| 240 | $i++; |
|
| 241 | } |
|
| 242 | } |
|
| 243 | } |
|
| 244 | ||
| 245 | /** |
|
| 246 | * Delete a node in the given position and returns it back. |
|
| @@ 158-174 (lines=17) @@ | ||
| 155 | * |
|
| 156 | * @return null if the head is null (or list is empty) |
|
| 157 | */ |
|
| 158 | public function getAll() { |
|
| 159 | if($this->head === null) { |
|
| 160 | return; |
|
| 161 | } |
|
| 162 | ||
| 163 | if($this->head === $this->tail) { |
|
| 164 | yield $this->head->data; |
|
| 165 | } else { |
|
| 166 | $current = $this->head; |
|
| 167 | $i = 0; |
|
| 168 | while($i < $this->size) { |
|
| 169 | yield $current->data; |
|
| 170 | $current = $current->next; |
|
| 171 | $i++; |
|
| 172 | } |
|
| 173 | } |
|
| 174 | } |
|
| 175 | ||
| 176 | /** |
|
| 177 | * Inserts data in the specified position. |
|