A site for interview questions and answers .
Perhaps you may like this too:static Node ReverseLinkedListRecursively(Node node, Node next){ if(node == null) return null; if (node.Next == null) { node.Next = next; return node; } Node tempNext = node.Next; node.Next = next; return ReverseLinkedListRecursively(tempNext, node);}Invoke this as such: ReverseLinkedListRecursively(head, null);
Thank u for ur comment . your code looks great and easy to understand .
Post a Comment
2 comments:
Perhaps you may like this too:
static Node ReverseLinkedListRecursively(Node node, Node next)
{
if(node == null)
return null;
if (node.Next == null)
{
node.Next = next;
return node;
}
Node tempNext = node.Next;
node.Next = next;
return ReverseLinkedListRecursively(tempNext, node);
}
Invoke this as such: ReverseLinkedListRecursively(head, null);
Thank u for ur comment . your code looks great and easy to understand .
Post a Comment