def main(): linknode1 = LinkedNode() value_list = np.sort(np.random.randint(1, 7, 6)) for i in value_list: node = Node(i) linknode1.add(node) print('The LinkedNode1 is: ' + linknode1.__str__()) linknode2 = LinkedNode() value_list = np.sort(np.random.randint(1, 10, 6)) for i in value_list: node = Node(i) linknode2.add(node) print('The LinkedNode2 is: ' + linknode2.__str__()) linknode3 = Solution_25() result = linknode3.merge(linknode1.head, linknode2.head) print('After merge the two LinkedNode:') while result.next is not None: print(result.data, end=', ') result = result.next print(result.data, end=', ')
def main(): linkedtable = LinkedNode() for i in np.random.randint(2, 15, 10).tolist(): node = Node(i) linkedtable.add(node) print('The linked node before modified is: ' + linkedtable.__str__()) delete_duplication(linkedtable) print('The linked node after modified is: ' + linkedtable.__str__())
def main(): linknode = LinkedNode() value_list = np.random.randint(1, 7, 6).tolist() for i in value_list: node = Node(i) linknode.add(node) print('The LinkedNode is: ' + linknode.__str__()) k = value_list[np.random.randint(1, 6)] print('The number to be deleted is: ' + str(k)) outputnode = Solution_22() outputnode.output_k_node_in_linkednode(linknode, k)
def main(): linkedtable = LinkedNode() for i in np.random.randint(2, 15, 10).tolist(): node = Node(i) linkedtable.add(node) print('The linked node before modified is: ' + linkedtable.__str__()) listofnode = linkedtable.listofnode() print('The list of node is: ', listofnode) tobedeletednode = listofnode[9] deletenode(linkedtable, tobedeletednode) # print('The value of node to be deleted is %d, and the value of the next closing node is %s' % (tobedeletednode.data, tobedeletednode.next.data)) print('The linked node after modified is: ' + linkedtable.__str__())
def main(): linknode = LinkedNode() value_list = np.random.randint(1, 7, 6).tolist() for i in value_list: node = Node(i) linknode.add(node) print('The LinkedNode is: ' + linknode.__str__()) reverselinkednode = Solution_24() reversenode = reverselinkednode.reverse_linkednode(linknode.head) reversehead = reversenode while reversehead.next is not None: print(reversehead.data, end=', ') reversehead = reversehead.next print(reversehead.data, end=', ')
def main(): ls1 = [1, 2, 3, 4, 5, 6, 7, 8] # ls2 = [0, 5, 6, 7, 8] ls2 = [9, 10, 11, 12] # 创建链表 link1 = LinkedNode() link2 = LinkedNode() for i in ls1: link1.add(i) for j in ls2: link2.add(j) # print(link2.listofnode()) commom_node = Solution_52().find_first_common_node(link1.head, link2.head) if commom_node: print('Two list node\'s commom node are %d.' % commom_node.data) else: print('Two list node have not commom node.')