Here is my code to reverse link list in using recursion:
Node n = null;
private void ReverseList(Node temp)
{
if (temp == null)
return;
ReverseList(temp.nextNode);
Node newNode = temp;
newNode.nextNode = null;
if (n == null)
{
n = newNode;
}
else
{
Node TempNode = n;
while (TempNode.nextNode != null)
{
TempNode = TempNode.nextNode;
}
TempNode.nextNode = newNode;
head=n;
}
}
Is this the preferred way of doing this? What modifications can I make to optimize this code?
head
variable not declared anywhere in the sources. – almaz Feb 19 at 13:21