Displaying the list backward

To display the list backward, we have to start from the last node and continue to move backward using the previous link until we reach the end of the list. This gives us a unique way of moving in any direction we need during operations. Here is the code for that:

    public function displayBackward() { 
echo "Total book titles: " . $this->_totalNode . " ";
$currentNode = $this->_lastNode;
while ($currentNode !== NULL) {
echo $currentNode->data . " ";
$currentNode = $currentNode->prev;
}
}
..................Content has been hidden....................

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