Further, we have another method given below:

/* next() class method */

bool next()

{

1.    if (currentNode  ==  NULL)   return    false;

2.

3.    lastCurrentNode  =  currentNode;

4.    currentNode  =  currentNode->getNext();

5.    return  true;

};

This is next() method, used to advance the currentNode pointer to the next node inside the linked list. At line 1, the currentNode is being checked to confirm that there are some elements present in the list to advance further. At line 1, the method is returning false if there is no element present in the list. At line 3, it is storing the value of the currentNode pointer into the lastCurrentNode. At line 4, currentNode is calling the getNext() method to get the address of next node to be stored in the currentNode pointer to advance the currentNode pointer to the next element. At line 5, it returns true indicating the method is successful in moving to the next node.

 

 

BACK

HOME

NEXT