class Node:
def __init__(self,item):
self.item = item
self.next = None
# a = Node(1)
# b = Node(2)
# c = Node(3)
# a.next = b
# b.next = c
#
# print(a.next.item)
#
# li = [1,2,3,4,5]
# li[2]
def create_linklist_head(li):#头插法,倒序插入
head = Node(li[0])
for element in li[1:]:
node = Node(element)
node.next = head
head = node
return head
def create_linklist_tail(li):#尾插,正序
head = Node(li[0])
tail = head
for element in li[1:]:
node = Node(element)
tail.next = node
tail = node
return head
def print_linklist(lk):
while lk:
print(lk.item,end = '')
lk = lk.next
def insert_linklist(p,curNode):
p.next = curNode.next
curNode.next = p
def del_linklist(p,curNode):
curNode.next = p.next
del p
lk = create_linklist_tail([1,2,3,6,8])
print_linklist(lk)