Understanding traversal
Traversal is the most fundamental operation on a doubly linked list and is the same as in a singly linked list. The extra information about the previous node that every node in a doubly linked list stores gives a doubly linked list the ability to traverse in two directions.
Forward Traversal
Forward traversal is moving from the head to the tail node in the doubly linked list. It is implemented in the same way as in a singly linked list. We use a variable that holds a reference to a node in the linked list as the loop control variable, and every time we want to move forward we assign the reference of the next node in the linked list to this variable. We can get the reference of the next node by looking at the node pointed by the next pointer of the current node.
Liking the course? Check our discounted plans to continue learning.