In this article we will discuss how to iterate over a LinkedList in reverse order.

Method 1 : Using Descending Iterator

Descending Iterator returns the Iterator that points to the end of of List i.e.

Now calling function next() with descending iterator will return the previous element and also moves the cursor by one position backward. Also, hasNext() will tell if previous element is available or not i.e.

Method 2 : Using Normal List Iterator

Get the list iterator that with index location List Size. This will make the iterator point to the end of List.

Now, use the ListIterator’s hasPrevious() function to check if previous element is present or not.

Then previous() function to fetch the previous element and move the cursor to previous element i.e.

Checkout the complete example to iterate over a LinkedList using both the above two methods as follows,



Python Recommendations:

C++ & C++11 Recommendations:

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Subscribe with us to join 1500+ Python & C++ developers, to get more Tips &  Tutorials like this.