Saturday, September 24, 2011

Reverse a Linked List - Recursive Solution

Function to reverse a linked list - recursive solution


void reverse(struct node *pred, struct node *curr)
{
  if(curr)
  {
    reverse(curr, curr -> link);
    curr -> link = pred;
  }
  else
    first = pred;
}

void main()
{
  reverse(NULL, first);
}

Written by

No comments:

Post a Comment