Recursive Solution approach in C++


#1

ListNode* reverse(ListNode* p,ListNode* prev)
{
if(p==NULL)
{
return prev;
}
ListNode *t=p->next;
p->next=prev;
prev=p;
return reverse(t,prev);
}

ListNode* Solution::reverseList(ListNode* A) {
ListNode *p=A, *prev=NULL;
return reverse(p,prev);
}