| @@ 46-60 (lines=15) @@ | ||
| 43 | * @param integer $index the position. |
|
| 44 | * @param mixed $data the data to store. |
|
| 45 | */ |
|
| 46 | public function insert($index, $data) { |
|
| 47 | if($index < 0) { |
|
| 48 | throw new OutOfBoundsException(); |
|
| 49 | } |
|
| 50 | ||
| 51 | if($index === 0) { |
|
| 52 | $this->insertBeginning($data); |
|
| 53 | } else if($index >= $this->size) { |
|
| 54 | $this->insertEnd($data); |
|
| 55 | } else if($index > 0 && $index < $this->size) { |
|
| 56 | $this->insertAt($index, $data); |
|
| 57 | } |
|
| 58 | $this->current = &$this->head; |
|
| 59 | $this->size++; |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * Inserts at the beginning of the list. |
|
| @@ 226-240 (lines=15) @@ | ||
| 223 | * @param integer $index the position. |
|
| 224 | * @param mixed $data the data to store. |
|
| 225 | */ |
|
| 226 | public function insert($index, $data) { |
|
| 227 | if($index < 0) { |
|
| 228 | throw new OutOfBoundsException(); |
|
| 229 | } |
|
| 230 | ||
| 231 | if($index === 0) { |
|
| 232 | $this->insertBeginning($data); |
|
| 233 | } else if($index >= $this->size) { |
|
| 234 | $this->insertEnd($data); |
|
| 235 | } else if($index > 0 && $index < $this->size) { |
|
| 236 | $this->insertAt($index, $data); |
|
| 237 | } |
|
| 238 | ||
| 239 | $this->size++; |
|
| 240 | } |
|
| 241 | ||
| 242 | /** |
|
| 243 | * Inserts at the beginning of the list. |
|