May 2017
Intermediate to advanced
340 pages
8h 16m
English
Since we are now tracking the last node, it will be easier to insert a new node at the end. First, we need to check that the list is not empty. If it is empty, then the new node becomes both the first and last node. However, if the list already has a last node, then we have to do the following:
Here is the code for that:
public function insertAtLast(string $data = NULL) { $newNode = new ListNode($data); if ($this->_firstNode === NULL) { $this->_firstNode = &$newNode; $this->_lastNode = $newNode; } else ...Read now
Unlock full access