Posted by hussein on July 14, 1999 at 23:35:52:
hi
for those of u still struggling with homework 5, try the following ...
think of a recursive function with the following definition :
reverse ( Node *before, Node *first )
where "before" is the address of the node before the sublist to be reversed, and first is the first node of the sublist to be reversed.
you would call this from the main program as "reverse (NULL, Head)".
now, in order to create the recursion, u need to adjust the Next pointer of the first node, and reverse the rest of the list ... and, as a termination condition, when the list to be reversed is empty it means the "before" Node is the last one and you can reset the Head pointer to point to it ...
this is pretty much the logic of one approach to the problem ... the actual code for this can be written very concisely ... (~5 lines)
hope this helps ...
ttfn
hussein