| @@ 45-59 (lines=15) @@ | ||
| 42 | * @param integer $index the position. |
|
| 43 | * @param mixed $data the data to store. |
|
| 44 | */ |
|
| 45 | public function insert($index, $data) { |
|
| 46 | if($index < 0) { |
|
| 47 | throw new OutOfBoundsException(); |
|
| 48 | } |
|
| 49 | ||
| 50 | if($index === 0) { |
|
| 51 | $this->insertBeginning($data); |
|
| 52 | } else if($index >= $this->size) { |
|
| 53 | $this->insertEnd($data); |
|
| 54 | } else if($index > 0 && $index < $this->size) { |
|
| 55 | $this->insertAt($index, $data); |
|
| 56 | } |
|
| 57 | $this->current = &$this->head; |
|
| 58 | $this->size++; |
|
| 59 | } |
|
| 60 | ||
| 61 | /** |
|
| 62 | * Inserts at the beginning of the list. |
|
| @@ 258-272 (lines=15) @@ | ||
| 255 | * @param integer $index the position. |
|
| 256 | * @param mixed $data the data to store. |
|
| 257 | */ |
|
| 258 | public function insert($index, $data) { |
|
| 259 | if($index < 0) { |
|
| 260 | throw new OutOfBoundsException(); |
|
| 261 | } |
|
| 262 | ||
| 263 | if($index === 0) { |
|
| 264 | $this->insertBeginning($data); |
|
| 265 | } else if($index >= $this->size) { |
|
| 266 | $this->insertEnd($data); |
|
| 267 | } else if($index > 0 && $index < $this->size) { |
|
| 268 | $this->insertAt($index, $data); |
|
| 269 | } |
|
| 270 | ||
| 271 | $this->size++; |
|
| 272 | } |
|
| 273 | ||
| 274 | /** |
|
| 275 | * Inserts at the beginning of the list. |
|
| @@ 198-212 (lines=15) @@ | ||
| 195 | * @param integer $index position |
|
| 196 | * @param mixed $data data to be saved |
|
| 197 | */ |
|
| 198 | public function insert($index, $data) { |
|
| 199 | if($index < 0) { |
|
| 200 | throw new OutOfBoundsException(); |
|
| 201 | } |
|
| 202 | ||
| 203 | if($index === 0) { |
|
| 204 | $this->insertBeginning($data); |
|
| 205 | } else if($index >= $this->size) { |
|
| 206 | $this->insertEnd($data); |
|
| 207 | } else if($index > 0 && $index < $this->size) { |
|
| 208 | $this->insertAt($index, $data); |
|
| 209 | } |
|
| 210 | ||
| 211 | $this->size++; |
|
| 212 | } |
|
| 213 | ||
| 214 | /** |
|
| 215 | * Add a new node in the specified index. |
|