def print_it(l1, l2, n): for i in range(n): from linked_list import LinkedList from linked_list_node import LinkedListNode from print_list import print_list_with_forward_arrow def merge_two_lists(head1, head2): dummy = LinkedListNode(-1) prev = dummy while head1 and head2: if head1.data <= head2.data: prev.next = head1 head1 = head1.next else: prev.next = head2 head2 = head2.next prev = prev.next if head1: prev.next = head1 else: prev.next = head2 return dummy.next # Driver code def main(): input = ( [[1, 2, 3],[1, 2, 3]], [[25, 33, 99], [1]], [[], [1]], [[-77, 0, 5], [1, 2, 7]], [[], []], ) for i in range(len(input)): list1 = LinkedList() list2 = LinkedList() list1.create_linked_list(input[i][0]) list2.create_linked_list(input[i][1]) print(i+1, ".\tInput: ") print("\t", end = " ") print_list_with_forward_arrow(list1.head) print("\n\t", end = " ") print_list_with_forward_arrow(list2.head) print("\n\n\tOutput: ") print("\t", end = " ") merged = merge_two_lists(list1.head, list2.head) print_list_with_forward_arrow(merged) print("\n", "-"*100) if __name__ == "__main__": main()