Originally Posted by iMalc
Absolutely not. No STL data structure will ever provide random access where it would take a linear amount of time i.e. O(n)
You absolutely MUST get rid of your getNodeAddress function altogether, and stop treating a list like an array. The whole idea of performing item swaps can be totally thrown out the window when it comes to lists. Please ignore the code xeddiex posted because it too makes this same mistake!
You can reverse the list without ever having the slightest clue how long it is. This is very very important and you should think about it for a while. Get rid of that "count" variable!
Here's an exersize you can try to help shift your thinking, such that you may understand how to solve the problem:
Make a stack of something on your desk (blocks, mail, books, whatever you like). Actually put them on top of one another in a pile.
Okay, now reverse the order of the items on your desk, such that the item that is now on the top wil be on the bottom. But the catch is, you cannot touch any object except one that is on the top of a pile.
Well, the first step is easy, you simply lift the top item off the top and put it in a new pile. This one needs to go on the bottom, so it can just stay where you put it... Now keep going!