| @@ 65-79 (lines=15) @@ | ||
| 62 | * @param integer $index the position. |
|
| 63 | * @param mixed $data the data to store. |
|
| 64 | */ |
|
| 65 | public function insert($index, $data) { |
|
| 66 | if($index < 0) { |
|
| 67 | throw new OutOfBoundsException(); |
|
| 68 | } |
|
| 69 | ||
| 70 | if($index === 0) { |
|
| 71 | $this->insertBeginning($data); |
|
| 72 | } else if($index >= $this->size) { |
|
| 73 | $this->insertEnd($data); |
|
| 74 | } else if($index > 0 && $index < $this->size) { |
|
| 75 | $this->insertAt($index, $data); |
|
| 76 | } |
|
| 77 | ||
| 78 | $this->size++; |
|
| 79 | } |
|
| 80 | ||
| 81 | /** |
|
| 82 | * Inserts at the beginning of the list. |
|
| @@ 187-201 (lines=15) @@ | ||
| 184 | * @param integer $index the position. |
|
| 185 | * @param mixed $data the data to store. |
|
| 186 | */ |
|
| 187 | public function insert($index, $data) { |
|
| 188 | if($index < 0) { |
|
| 189 | throw new OutOfBoundsException(); |
|
| 190 | } |
|
| 191 | ||
| 192 | if($index === 0) { |
|
| 193 | $this->insertBeginning($data); |
|
| 194 | } else if($index >= $this->size) { |
|
| 195 | $this->insertEnd($data); |
|
| 196 | } else if($index > 0 && $index < $this->size) { |
|
| 197 | $this->insertAt($index, $data); |
|
| 198 | } |
|
| 199 | ||
| 200 | $this->size++; |
|
| 201 | } |
|
| 202 | ||
| 203 | /** |
|
| 204 | * Inserts at the beginning of the list. |
|