我知道这是一个分钟代码。我不明白为什么我的链表反转不起作用。有人可以帮我在下面的代码中修复我的反向方法吗?
//Reverse a single linked list
public Node reverse()
{
return reverse(root);
}
private Node reverse(Node node)
{
Node previous = null;
Node current = node;
Node forward;
while (current != null)
{
forward = current.next;
current.next = previous;
previous = current;
current = forward;
}
return previous;
}
对此的任何输入都会有所帮助
谢谢 !!!