We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Node* Reverse(Node *head)
{
// The tail of the list has been reached which
// will now be the new head of the reversed list
if (head == NULL || head->next == NULL) {
return head;
}
Node* nextNode = head->next;
head->next = NULL;
Node* newHead = Reverse(nextNode);
// reverse the nodes
nextNode->next = head;
return newHead;
}
Reverse a linked list
You are viewing a single comment's thread. Return to all comments →
Recursive implementation in C: