任何人都可以共享代码的链接,解释如何撤消linked list?或者有人可以解释下面的代码片段吗?
我试图绘制/写入它,但仍然没有得到节点如何反转.
public void reverseList() {
Node reversedPart = null;
Node current = head;
while (current != null) {
Node next = current.next;
current.next = reversedPart;
reversedPart = current;
current = next;
}
head = reversedPart;
}
Run Code Online (Sandbox Code Playgroud)