title: How does traverse backward work for a Doubly Linked List in Java?
body: <p>My understanding of traversing backwards in a doubly linked list is traversing from some position back to the first node in the list. I have written a Doubly Linked List class in java, and a traverseBack method in it. </p>
  
  <p>The code for the traverseBack method is as follows.</p>
  
  <pre><code>public void traverseBack(int d){
      for(Node n=first; n!=null; n=n.next){
          if(n.data == d){
              System.out.println("\nTraversing in Backward Direction\n");
              while(n!=null){
                  System.out.println(n.data);
                  n = n.prev;
              }
              return;
          }
          if(n.next==null){
              System.out.println("Given node doesn't exist");
              return;
          }
      }
  }
  </code></pre>
  
  <p>The code was compiled and run without errors. </p>
  
  <p>Can I ask whether my understanding of traversing backwards in a doubly linked list is correct or not? Is there anything in the code that I haven't done well?</p>