| @@ 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 | ||
| 59 | $this->size++; | |
| 60 | } | |
| 61 | ||
| 62 | /** | |
| 63 | * Inserts at the beginning of the list. | |
| @@ 181-195 (lines=15) @@ | ||
| 178 | * @param integer $index the position. | |
| 179 | * @param mixed $data the data to store. | |
| 180 | */ | |
| 181 |     public function insert($index, $data) { | |
| 182 |         if($index < 0) { | |
| 183 | throw new OutOfBoundsException(); | |
| 184 | } | |
| 185 | ||
| 186 |         if($index === 0) { | |
| 187 | $this->insertBeginning($data); | |
| 188 |         } else if($index >= $this->size) { | |
| 189 | $this->insertEnd($data); | |
| 190 |         } else if($index > 0 && $index < $this->size) { | |
| 191 | $this->insertAt($index, $data); | |
| 192 | } | |
| 193 | ||
| 194 | $this->size++; | |
| 195 | } | |
| 196 | ||
| 197 | /** | |
| 198 | * Inserts at the beginning of the list. | |