The structure of the linked list is:
struct ListNode
{
int M_nkey;
Listnode* Next;
};
From the beginning to the end of the output chain list for everyone is relatively simple, but from the tail should be how to do it?
In fact, you can think of this, from beginning to end the chain list, and put the data of the linked list into the stack, when traversing to the tail of the list, and then output data from the stack, the resulting value is from the tail to output the value of the head,
But in this implementation, it is necessary to maintain a stack, but also very troublesome, at this time you can think about the implementation of the stack and recursive implementation of the same, then it is possible not to use the stack, but the use of recursive implementation?
Is it easier to understand and not to maintain stacks? This is possible.
1 voidReverselist (listnode*plisthead)2 {3 if(Plisthead! =NULL)4 {5 6 if(Plisthead->m_pnext! =NULL)7 {8Reverselist (plisthead->next);9 }Ten One Aprintf"%d", plisthead->m_nkey); - } -}
Output linked list from tail to head