/* copyright (c) 2004-2010 by Ludo Smissaert */ /* * An answer for ``Problem 18'' of LinkedListProblems: * recursively reverse a linked list. */ void RecursiveReverse(struct node **headRef) { struct node *p; /* pointer to last node after * each recursive call */ if (!(*headRef)->next) return; p = (*headRef)->next; /* will not be the last node now, * but it *will* be after the * "train of recursion" returns!!! */ RecursiveReverse(&(*headRef)->next); p->next = *headRef; *headRef = (*headRef)->next; p->next->next = NULL; }