void reverse(NODE **head) {
if (!*head) return;
NODE *cur = *head;
NODE *prev = NULL;
NODE *next = NULL;
while (cur) {
next = cur->next;
cur->next = prev;
prev = cur;
cur = next;
}
*head = prev;
return;
}
Recusive way call with original = list, parent = NULL
Node* reverselinkedlist(Node* original, Node*parent)
{
Node* reverse;
if(original == NULL)
{
reverse = parent;
}
else
{
reverse = reverselinkedlist(original->link,original);
original->link = parent;
}
return reverse;
}
No comments:
Post a Comment