@@ 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. |