def reverse_linked_list(head):
if not head or not head. next :
return head
prev_node = None
current_node = head
next_node = head. next
while True :
current_node. next = prev_node
if not next_node:
break
prev_node = current_node
current_node = next_node
next_node = current_node. next
return current_node
new_head = reverse_linked_list(head)
print ( '逆置之后的链表' )
print (new_head.value)
print (new_head. next .value)
print (new_head. next . next .value)
print (new_head. next . next . next .value)
print (new_head. next . next . next . next .value)
print (new_head. next . next . next . next . next .value)
|