May 2017
Intermediate to advanced
340 pages
8h 16m
English
When we add a node at the front or head, we have to check whether the list is empty or not. If the list is empty, both the first and last node will point to the newly created node. However, if the list already has a head, then we have to do the following:
Here is the code for that:
public function insertAtFirst(string $data = NULL) { $newNode = new ListNode($data); if ($this->_firstNode === NULL) { $this->_firstNode = &$newNode; $this->_lastNode = $newNode; } else { $currentFirstNode ...Read now
Unlock full access