May 2017
Intermediate to advanced
340 pages
8h 16m
English
Deleting the last node will require us to assign the second from last node's next link to NULL. We will iterate until the last node and track the previous node as we go. Once we hit the last node, the previous node property of the next will be set to NULL, as shown in the following example:
public function deleteLast() { if ($this->_firstNode !== NULL) { $currentNode = $this->_firstNode; if ($currentNode->next === NULL) { $this->_firstNode = NULL; } else { $previousNode = NULL; while ($currentNode->next !== NULL) { $previousNode = $currentNode; $currentNode = $currentNode->next; } $previousNode->next = NULL; $this->_totalNode--; return TRUE; } } return FALSE; }
At first, we check whether the list ...
Read now
Unlock full access