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
|
@@ 254-262 (lines=9) @@
|
251 |
|
/** |
252 |
|
* {@inheritDoc} |
253 |
|
*/ |
254 |
|
protected function insertBeginning($data) { |
255 |
|
$newNode = new SimpleLinkedListNode($data); |
256 |
|
if($this->head === null) { |
257 |
|
$this->head = &$newNode; |
258 |
|
} else { |
259 |
|
$newNode->next = $this->head; |
260 |
|
$this->head = &$newNode; |
261 |
|
} |
262 |
|
} |
263 |
|
|
264 |
|
/** |
265 |
|
* Delete a node in the given position and returns it back. |