# -*- coding:utf-8 -*-
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None


# 翻转链表
# 链表

class Solution:
    # 返回ListNode
    def ReverseList(self, head):
        p = None
        while head:
            tmp = head.next

            head.next = p
            p = head

            head = tmp
        return p


if __name__ == '__main__':
    s = Solution()
    l1 = ListNode(1)
    l2 = ListNode(2)
    l3 = ListNode(3)
    l4 = ListNode(4)
    l5 = ListNode(5)

    l1.next = l2
    l2.next = l3
    l3.next = l4
    l4.next = l5

    p = s.ReverseList(l1)

    while p != None:
        print p.val
        p = p.next
