def test(arr1, arr2, comment=None): print("=" * 80) if comment: print(comment) print(f"\narr1 = {arr1}") print(f"arr2 = {arr2}") head1, _ = build_ll(arr1) head2, _ = build_ll(arr2) res = sol.mergeTwoLists(head1, head2) print(f"\n{res}\n")
def test(arr): head, _ = build_ll(arr) #root = build_bst(head) root = build_bst2(head) print("#" * 80) print(arr) print() print_tree(root)
def test(arr, comment=None): print("=" * 80) if comment: print(comment) head, _ = build_ll(arr) print(f"\narr = {arr}") res = sol.oddEvenList(head) print(f"\nres = {res}\n")
def test(arr, comment=None): print("=" * 80) if comment: print(comment) print(f"\narr = {arr}") head, _ = build_ll(arr) res = sol.sortList(head) print(f"\n{res}\n")
def test(arr, comment=None): print("=" * 80) if comment: print(comment) head, _ = build_ll(arr) print() print(head) res = sol.deleteDuplicates(head) print(f"\n{res}\n")
def test(arr, comment=None): print("=" * 80) if comment: print(comment) head, _ = build_ll(arr) print() print(head) res = sol.nextLargerNodes(head) print(f"\n{res}\n")
def test(arr, val, comment=None): print("="*80) if comment: print(comment) head, _ = build_ll(arr) print() print(head) print(f"val = {val}") res = sol.removeElements(head, val) print(f"\nAfter: {res}\n")
def test(arrays, comment=None): lists = [] for arr in arrays: lists += [build_ll(arr)[0]] print("=" * 80) if comment: print(comment) # lists are modified after the merge print("\nOriginal sorted lists:") for ll in lists: print(ll) head = s.mergeKLists(lists) print("\nSorted, merged linked list:") print(head) print()
def test(arr, node_val, comment=None): print("=" * 80) if comment: print(comment) print() print(arr) head, _ = build_ll(arr) print(head) print(f"\nhead = {head}") node = head while node.val != node_val: node = node.next print(f"\nnode value = {node_val}") sol.deleteNode(node) print(head) print()
def test_self_merge(arr): lst = build_ll(arr)[0] _ = s.mergeKLists([lst, lst]) # infinite loop