defbuild_linked_list(values): ifnot values: returnNone root = Node(values[0]) p_node = root for value in values[1:]: p_node.next = Node(value) p_node = p_node.next return root
defmain(): p_head = build_linked_list([1, 2, 3, 4, 5]) node_3 = p_head.next.next# Node<3> delete_node(p_head, node_3) for node in travel_list(p_head): print(node, end='\t')
print('\n') print('delete last node') node_5 = p_head.next.next.next delete_node(p_head, node_5) for node in travel_list(p_head): print(node, end='\t')