This is a tail-recursive solution for reversing a singly linked list. What is the auxiliary space occupied by this solution?
void reverseUtil(Node* curr, Node* prev, Node** head)
{
if (curr->next==NULL) {
*head = curr;
curr->next = prev;
return;
}
Node* next = curr->next;
curr->next = prev;
reverseUtil(next, curr, head);
}
void reverse(Node** head)
{
if (head==NULL)
return;
reverseUtil(*head, NULL, head);
}