| @@ 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. |
|
| @@ 203-217 (lines=15) @@ | ||
| 200 | * @param integer $index the position. |
|
| 201 | * @param mixed $data the data to store. |
|
| 202 | */ |
|
| 203 | public function insert($index, $data) { |
|
| 204 | if($index < 0) { |
|
| 205 | throw new OutOfBoundsException(); |
|
| 206 | } |
|
| 207 | ||
| 208 | if($index === 0) { |
|
| 209 | $this->insertBeginning($data); |
|
| 210 | } else if($index >= $this->size) { |
|
| 211 | $this->insertEnd($data); |
|
| 212 | } else if($index > 0 && $index < $this->size) { |
|
| 213 | $this->insertAt($index, $data); |
|
| 214 | } |
|
| 215 | ||
| 216 | $this->size++; |
|
| 217 | } |
|
| 218 | ||
| 219 | /** |
|
| 220 | * Inserts at the beginning of the list. |
|