python 链表实现方式
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
def LinkedList(a):
L = ListNode(a[0])
l = L
for i in range(1, len(a)):
L.next = ListNode(a[i])
L = L.next
return l
def printl(a):
out = []
while a:
out.append(a.val)
a = a.next
print(out)
a = [1,2,3,4]
l = LinkedList(a)
printl(l)