DataStructures/Lists/CircularLinkedList.php 1 location
|
@@ 85-90 (lines=6) @@
|
| 82 |
|
* @param integer $index the position. |
| 83 |
|
* @param mixed $data the data to be stored. |
| 84 |
|
*/ |
| 85 |
|
private function insertEnd($data) { |
| 86 |
|
$newNode = new SimpleLinkedListNode($data); |
| 87 |
|
$this->tail->next = &$newNode; |
| 88 |
|
$newNode->next = &$this->head; |
| 89 |
|
$this->tail = &$newNode; |
| 90 |
|
} |
| 91 |
|
|
| 92 |
|
/** |
| 93 |
|
* Add a new node in the specified index. |
DataStructures/Lists/SimpleLinkedList.php 1 location
|
@@ 249-257 (lines=9) @@
|
| 246 |
|
} |
| 247 |
|
} |
| 248 |
|
|
| 249 |
|
protected function insertBeginning($data) { |
| 250 |
|
$newNode = new SimpleLinkedListNode($data); |
| 251 |
|
if($this->head === null) { |
| 252 |
|
$this->head = &$newNode; |
| 253 |
|
} else { |
| 254 |
|
$newNode->next = $this->head; |
| 255 |
|
$this->head = &$newNode; |
| 256 |
|
} |
| 257 |
|
} |
| 258 |
|
|
| 259 |
|
/** |
| 260 |
|
* Delete a node in the given position and returns it back. |