单链表反转
原创
©著作权归作者所有:来自51CTO博客作者aaronthon的原创作品,请联系作者获取转载授权,否则将追究法律责任
# 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
结束!