先定义链表结点类
# 定义结点类
class Node:
def __init__(self, val):
self.val = val
self.next = None
def traverse(self):
cur = self
res = []
while cur is not None:
print(cur.val)
res.append(cur)
cur = cur.next
return res
先定义链表结点类
# 定义结点类
class Node:
def __init__(self, val):
self.val = val
self.next = None
def traverse(self):
cur = self
res = []
while cur is not None:
print(cur.val)
res.append(cur)
cur = cur.next
return res