DataStructures/Lists/CircularLinkedList.php 1 location
|
@@ 64-69 (lines=6) @@
|
| 61 |
|
* @param integer $index the position. |
| 62 |
|
* @param mixed $data the data to be stored. |
| 63 |
|
*/ |
| 64 |
|
protected function insertEnd($data) { |
| 65 |
|
$newNode = new SimpleLinkedListNode($data); |
| 66 |
|
$this->tail->next = &$newNode; |
| 67 |
|
$newNode->next = &$this->head; |
| 68 |
|
$this->tail = &$newNode; |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
/** |
| 72 |
|
* Add a new node in the specified index. |
DataStructures/Lists/SimpleLinkedList.php 1 location
|
@@ 230-238 (lines=9) @@
|
| 227 |
|
/** |
| 228 |
|
* {@inheritDoc} |
| 229 |
|
*/ |
| 230 |
|
protected function insertBeginning($data) { |
| 231 |
|
$newNode = new SimpleLinkedListNode($data); |
| 232 |
|
if($this->head === null) { |
| 233 |
|
$this->head = &$newNode; |
| 234 |
|
} else { |
| 235 |
|
$newNode->next = $this->head; |
| 236 |
|
$this->head = &$newNode; |
| 237 |
|
} |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
/** |
| 241 |
|
* Delete a node in the given position and returns it back. |