获取链表

获取链表

#!/usr/bin/env python
# -*- coding_utf-8 -*-

class ListNode:
    def __init__(self,x):
        self.val = x
        self.next  = None

class Get_linked_list:
    def __init__(self,l):
        self.l = l

    def get_data(self):
        if self.l == []:
            return None
        phead = ListNode(None)
        pcur = phead
        for i in self.l:
            pnode = ListNode(i)
            pcur.next = pnode
            pcur = pcur.next
        return phead.next

    def show_linked_list(self):

        t = self.get_data()
        res = ''
        while (t != None):
            res = res + str(t.val)+ '->'
            t = t.next
        res += 'None'
        print(res)

if __name__ == '__main__':
    ll = Get_linked_list([1,2,3,4,5,6])
    r = ll.get_data()

    ll.show_linked_list()