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.

Similar Reads

Types of Traversal in Doubly Linked List Using JavaScript

Normal Traversal: Traversing the list from Head to Tail of the list. Reverse Traversal: Traversing the list from the Tail element to the Head element of the list i.e. in reverse order....

Normal traversal

This is head to tail movement of the pointer in a list. The normal traversal is done as:...

Reverse traversal

...

Implementation of traversal in Doubly Linked List

This is head to tail movement of the pointer in a list. The normal traversal is done as:...

Contact Us