Node reverse(Node head) {
Node previous = null;
Node current = head;
Node forward;
while (current != null) {
forward = current.next;
current.next = previous;
previous = current;
current = forward;
}
return previous;
}
它究竟如何反轉列表?我知道它首先將第二個節點設置爲forward
。然後它說current.next
等於null
節點previous
。然後它說previous
現在是current
。最後current
變成forward
?如何反轉鏈接列表?
我似乎無法理解這一點,以及它如何逆轉。有人可以解釋這是如何工作的?
這是python? – Ben 2012-01-31 09:08:55
'從__future__進口支架'? – Johnsyweb 2012-01-31 09:11:30
我的錯..固定在java! – user1176235 2012-01-31 09:12:07