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 test_insert(): list = LinkedNode(10) list += 30 list += 40 list += 50 assert repr(list) == '10' assert repr(list.next_node.key) == '30' assert print_list(list) == '10, 30, 40, 50'
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(): 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.')
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 test_delete(): list = LinkedNode(10) list += 20 list += 30 list += 40 list = delete_item(list, 30) assert print_list(list) == '10, 20, 40' list = delete_item(list, 10) assert print_list(list) == '20, 40' list = delete_item(list, 50) assert print_list(list) == '20, 40' list = delete_item(list, 40) assert print_list(list) == '20' list = delete_item(list, 20) assert type(list) == NoneType
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 test_create_empty(): list = LinkedNode(10) assert list.key == 10
def parse(data): initNode = None prevNode = None curNode = None lowerBound = {} upperBound = {} y_min = [float("inf") for _ in range(len(data[2].strip().split()))] y_max = [float("-inf") for _ in range(len(data[2].strip().split()))] for line in data: # This is a mode indicator if ',' in line or '->' in line or line.strip().isalpha() or len( line.strip()) == 1: insertData(curNode, lowerBound, upperBound) # There is new a transition if '->' in line: modeList = line.strip().split('->') prevNode = initNode for i in range(1, len(modeList) - 1): prevNode = prevNode.child[modeList[i]] curNode = prevNode.child.setdefault( modeList[-1], LinkedNode(modeList[-1], line)) else: curNode = LinkedNode(line.strip(), line) if not initNode: initNode = curNode else: curNode = initNode # Using dictionary becasue we want to concat data lowerBound = {} upperBound = {} LOWER = True else: line = map(float, line.strip().split()) if len(line) <= 1: continue if LOWER: LOWER = False # This data appered in lowerBound before, concat the data if line[0] in lowerBound: for i in range(1, len(line)): lowerBound[line[0]][i] = min(lowerBound[line[0]][i], line[i]) else: lowerBound[line[0]] = line for i in range(len(line)): y_min[i] = min(y_min[i], line[i]) else: LOWER = True if line[0] in upperBound: for i in range(1, len(line)): upperBound[line[0]][i] = max(upperBound[line[0]][i], line[i]) else: upperBound[line[0]] = line for i in range(len(line)): y_max[i] = max(y_max[i], line[i]) insertData(curNode, lowerBound, upperBound) return initNode, y_min, y_max