All pastes #829024 Raw Edit

Mine

public text v1 · immutable
#829024 ·published 2007-12-22 21:44 UTC
rendered paste body
//Standford's solution:

void RecursiveReverse(struct node** headRef) {
   struct node* first;
   struct node* rest;
   if (*headRef == NULL) return;          // empty list base case
   first = *headRef;    // suppose first = {1, 2, 3}
   rest = first->next;  //         rest = {2, 3}
   if (rest == NULL) return;        // empty rest base case
   RecursiveReverse(&rest);   // Recursively reverse the smaller {2, 3} case
                              // after: rest = {3, 2}
   first->next->next = first; // put the first elem on the end of the list
   first->next = NULL;        // (tricky step -- make a drawing)
   *headRef = rest;     // fix the head pointer
}

//Mine:

void recursive_reversel(struct linked_list** list) {
    struct linked_list* current = *list;
    struct linked_list* next;
    struct linked_list* holder;

    next = holder = current->next;

    if(next){
        current->next = NULL; 
        recursive_reversel(&next);
        *list = next; 
        holder->next = current; 
    }

}