| @@ 211-227 (lines=17) @@ | ||
| 208 | * |
|
| 209 | * @return null if the head is null (or list is empty) |
|
| 210 | */ |
|
| 211 | public function getAll() { |
|
| 212 | if($this->head === null) { |
|
| 213 | return; |
|
| 214 | } |
|
| 215 | ||
| 216 | if($this->head->next === $this->tail) { |
|
| 217 | yield $this->head->data; |
|
| 218 | } else { |
|
| 219 | $current = $this->head; |
|
| 220 | $i = 0; |
|
| 221 | while($i < $this->size) { |
|
| 222 | yield $current->data; |
|
| 223 | $current = $current->next; |
|
| 224 | $i++; |
|
| 225 | } |
|
| 226 | } |
|
| 227 | } |
|
| 228 | ||
| 229 | /** |
|
| 230 | * Delete a node in the given position and returns it back. |
|
| @@ 136-152 (lines=17) @@ | ||
| 133 | * |
|
| 134 | * @return null if the head is null (or list is empty) |
|
| 135 | */ |
|
| 136 | public function getAll() { |
|
| 137 | if($this->head === null) { |
|
| 138 | return; |
|
| 139 | } |
|
| 140 | ||
| 141 | if($this->head === $this->tail) { |
|
| 142 | yield $this->head->data; |
|
| 143 | } else { |
|
| 144 | $current = $this->head; |
|
| 145 | $i = 0; |
|
| 146 | while($i < $this->size) { |
|
| 147 | yield $current->data; |
|
| 148 | $current = $current->next; |
|
| 149 | $i++; |
|
| 150 | } |
|
| 151 | } |
|
| 152 | } |
|
| 153 | ||
| 154 | /** |
|
| 155 | * Inserts data in the specified position. |
|