May 2017
Intermediate to advanced
340 pages
8h 16m
English
When we add a node in the front, or head, we have to consider two simple possibilities. The list can be empty and as a result the new node is the head. This possibility is as simple as it can get. However, if the list already has a head, then we have to do the following:
Here is the code for this:
public function insertAtFirst(string $data = NULL) { $newNode = new ListNode($data); if ($this->_firstNode === NULL) { $this->_firstNode = &$newNode; } else { $currentFirstNode = $this->_firstNode; $this->_firstNode = &$newNode; $newNode->next = $currentFirstNode; ...Read now
Unlock full access