单链表反转
# coding: utf-8 class Node(object): def __init__(self, data, next=None): self.data = data self.next = next def reverserNode(head): if head == Node or head.next == None: return head probe = None next = None while head != None: next = head.next head.next = probe probe = head head = next return probe if __name__ == "__main__": head = None for i in range(1,6): head = Node(i, head) liNode = reverserNode(head) while liNode != None: print liNode.data liNode = liNode.next
结束!