| @@ 276-292 (lines=17) @@ | ||
| 273 | /** |
|
| 274 | * |
|
| 275 | */ |
|
| 276 | public function remove($data) { |
|
| 277 | $current = $this->head; |
|
| 278 | $prev = $this->tail; |
|
| 279 | $i = 0; |
|
| 280 | ||
| 281 | while($i < $this->size) { |
|
| 282 | if($pev->data === $data) { |
|
| 283 | $prev->next = &$current->next; |
|
| 284 | return $current->data; |
|
| 285 | } |
|
| 286 | ||
| 287 | $prev = $current; |
|
| 288 | $current = $current->next; |
|
| 289 | } |
|
| 290 | ||
| 291 | return null; |
|
| 292 | } |
|
| 293 | ||
| 294 | /** |
|
| 295 | * Generator for retrieve all nodes stored. |
|
| @@ 372-387 (lines=16) @@ | ||
| 369 | * @param integer $index the position. |
|
| 370 | * @return mixed the data stored in the node. |
|
| 371 | */ |
|
| 372 | private function deleteAt($index) { |
|
| 373 | $i = 0; |
|
| 374 | $prev = $this->head; |
|
| 375 | $current = $this->head; |
|
| 376 | ||
| 377 | while($i < $index) { |
|
| 378 | $prev = $current; |
|
| 379 | $current = $current->next; |
|
| 380 | $i++; |
|
| 381 | } |
|
| 382 | ||
| 383 | $prev->next = &$current->next; |
|
| 384 | $this->size--; |
|
| 385 | ||
| 386 | return $current->data; |
|
| 387 | } |
|
| 388 | ||
| 389 | /** |
|
| 390 | * Deletes at the end of the list and returns the data stored. |
|