Quote Originally Posted by nuzzle View Post
It works because of recursion (a function calls itself repeatedly until a termination criterion is met).

Here the ReadListBackward function is calling itself and each time advancing along the list in the forward direction. Finally when the end is reached all accumulated ReadListBackward calls are terminated in reverse order one by one. It's during this "rewinding" process the printing takes place so it will be in reverse. If you put the print immediately before the ReadListBackward call the order would be in the forward direction instead.

A warning. If the list is very long the number of accumulated ReadListBackward calls may be too many which will result in a stack overflow.

And the ReadListBackward function is little too complicated. It's possible to do this with just one print statement.
Thanks for your reply. First of all, let me take an example here,
assume there is four nodes in the list, node 1, node 2, node 3, node 4 like this,

1=>2=>3=>4

So the calling sequence would be like this,

ReadListBackward(1)=>ReadListBackward(2)=>ReadListBackward(3)=>ReadListBackward(4)=>print(4)=>return

So when ReadListBackward(4) returns, the control goes to ReadListBackward(3). Here what I really don't understand is that since node 3's next node is always not NULL, so how come it will print out 3? Thanks a lot.