C++ - How to traverse a list from end to begin?

c++, for-loop, list, stl

Solution

Use rbegin and rend to get reverse iterators.

for (std::list<...>::reverse_iterator it=list.rbegin(); it!=list.rend(); ++it)

Problem

I would like to display my list from the end to the beginning. Like: ``` for (std::list<T>::const_iterator it = list.end(); it != list.begin(); --it) ``` The problem is that it doesn't enter in when it is in the first element (`list.begin()`). How can I do this?

Original source

Related problems