https://www.jb51.net/article/119500.htm
链表反转
1 class Node(): 2 def __init__(self,elem,next =None): 3 self.elem = elem 4 self.next = next 5 6 def reverse_list(head): 7 if head == None or head.next == None: 8 return head 9 10 pre = None 11 next = None 12 while head!=None: 13 next = head.next 14 head.next = pre 15 pre = head 16 head = next 17 return pre 18 19 li = Node(3) 20 li.next = Node(2) 21 li.next.next = Node(1) 22 li.next.next.next = Node(0) 23 24 l = reverse_list(li) 25 print(l.elem,l.next.elem,l.next.next.elem,l.next.next.next.elem)