Reverse traversal
This is head to tail movement of the pointer in a list. The normal traversal is done as:
- Create a pointer named curr as the current pointer.
- Assign the value of the tail to the curr pointer.
- Move the curr pointer backward till start and display output.
- curr => curr.prev
Example:
Javascript
// To display/ traverse list in reverse displayRev() { // Check if the List is empty if (! this .isEmpty()) { // traverse the list using new current pointer let curr = this .tail; console.log( 'Required list in reverse order is' ) while (curr !== null ) { // Display element console.log(curr.data); // Shift the current pointer curr = curr.prev; } } } |
How to traverse Doubly Linked List in JavaScript?
This article will demonstrate the Doubly Linked List Traversal using JavaScript. Traversal refers to the steps or movement of the pointer to access any element of the list.