Sunday, August 28, 2011

Reverse a Linked List


/* a function to sort reverse list */
struct node *reverse(struct node *p)
{
        struct node *prev, *curr,*next;
        prev = NULL;
        curr = p;
        while (curr != NULL)
        {
                next = curr-> link;
                curr-> link = prev;
                prev = curr;
                curr = next;
        }
        return(prev);
}

No comments:

Post a Comment