Deleting the last node

Deleting the last node requires us to set a second to last node as the new last node. Also, the newly created last node should not have any next reference. The code sample is shown here:

    public function deleteLast() { 
if ($this->_lastNode !== NULL) {

$currentNode = $this->_lastNode;
if ($currentNode->prev === NULL) {
$this->_firstNode = NULL;
$this->_lastNode = NULL;
} else {
$previousNode = $currentNode->prev;
$this->_lastNode = $previousNode;
$previousNode->next = NULL;
$this->_totalNode--;
return TRUE;
}
}
return FALSE;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset