今天在做一道【反转链表】的题,利用递归的方法时,遇到以下问题。请看代码
#代码块1
head.next, tail, head = tail, head, head.next
我自以为是,将上述代码改成
#代码块2
head.next=tail
tail=head
head=head.next
结果,当然是不对啊。代码块1和代码块2的意思完全不相同。
代码块1的意思是同时赋值。
代码块2即为分步赋值。
今天在做一道【反转链表】的题,利用递归的方法时,遇到以下问题。请看代码
#代码块1
head.next, tail, head = tail, head, head.next
我自以为是,将上述代码改成
#代码块2
head.next=tail
tail=head
head=head.next
结果,当然是不对啊。代码块1和代码块2的意思完全不相同。
代码块1的意思是同时赋值。
代码块2即为分步赋值。