Deleting a node simply means taking out the node and rearranging the previous and subsequent node links. If we just remove a node and connect the previous node's next link with the node following the deleted node, we are done with the delete operation. Just have a look at the following example:
When we delete the first node, we just have to make the second node our head or first node. We can achieve that very easily by using the following code:
public function deleteFirst() {
if ($this->_firstNode !== NULL) {
if ($this->_firstNode->next !== NULL) {
$this->_firstNode = $this->_firstNode->next;
} else {
$this->_firstNode = NULL;
}
$this->_totalNode--;
return TRUE;
}
return FALSE;
}
Now, we have to consider one special case, namely decreasing the total node count by one.