def run(a, prt=sys.stdout): desc = 'QUICKSORT PARTITION' ah = ArrayHistory() j = _partition(a, lo=0, hi=len(a)-1, array_history=ah) ah.prt() ah.show(desc) print desc, "RESULT:", ' '.join(str(e) for e in a)
def run(a): desc = 'QUICKSORT' ah = ArrayHistory() Sort(a, array_history=ah) ah.prt() ah.show(desc) print desc, "RESULT:", a
def run(a, desc=None, sort_seq=None, prt=sys.stdout): ah = ArrayHistory() Sort(a, array_history=ah, sort_seq=sort_seq) if desc is None: desc = "SHELL SORT" prt.write("{DESC} RESULT {A}\n".format(DESC=desc, A=' '.join(str(e) for e in a))) ah.prt() ah.show(desc)
def run(a, prt=sys.stdout): desc = 'QUICK3WAY' ah = ArrayHistory() # Do not shuffle so that we may better visualize _sort actions Sort(a, array_history=ah, shuffle=False) ah.prt() #ah.show(desc) prt.write("{DESC} RESULT: {A}\n".format(DESC=desc, A=' '.join([str(e) for e in a])))
def run(a, prt=sys.stdout): desc = 'QUICK3WAY' ah = ArrayHistory() # Do not shuffle so that we may better visualize _sort actions Sort(a, array_history=ah, shuffle=False) ah.prt() #ah.show(desc) prt.write("{DESC} RESULT: {A}\n".format( DESC=desc, A=' '.join([str(e) for e in a])))
def get_sort_history(lst): lst_Selection = copy.deepcopy(lst) lst_Insertion = copy.deepcopy(lst) lst_Shell = copy.deepcopy(lst) history_Selection = ArrayHistory() history_Insertion = ArrayHistory() history_Shell = ArrayHistory() Selection.Sort(lst_Selection, array_history=history_Selection) Insertion.Sort(lst_Insertion, array_history=history_Insertion) Shell.Sort(lst_Shell, array_history=history_Shell) return [history_Selection, history_Insertion, history_Shell]
def test_wk2_q2a(prt=sys.stdout): desc = 'SELECTION SORT WORDS' prt.write("\n{TEST}\n".format(TEST=desc)) exp = "BECK BUSH DEVO EVE6 HOLE JAYZ KORN MIMS VAIN RATT TOTO PINK SADE NOFX SOAD WHAM" a = "HOLE BUSH MIMS BECK WHAM SOAD NOFX TOTO VAIN RATT DEVO PINK SADE KORN JAYZ EVE6".split() ah = ArrayHistory() Sort(a, array_history=ah) ah.show(desc) for idx, A in enumerate(ah): if chk( A[0], exp ): prt.write("MATCH {I}\n".format(I=idx))
def test_wk2_q2a(prt=sys.stdout): desc = 'SELECTION SORT WORDS' prt.write("\n{TEST}\n".format(TEST=desc)) exp = "BECK BUSH DEVO EVE6 HOLE JAYZ KORN MIMS VAIN RATT TOTO PINK SADE NOFX SOAD WHAM" a = "HOLE BUSH MIMS BECK WHAM SOAD NOFX TOTO VAIN RATT DEVO PINK SADE KORN JAYZ EVE6".split( ) ah = ArrayHistory() Sort(a, array_history=ah) ah.show(desc) for idx, A in enumerate(ah): if chk(A[0], exp): prt.write("MATCH {I}\n".format(I=idx))
def run(a): desc = 'QUICKSORT' ah = ArrayHistory() Sort(a, array_history=ah) ah.prt() ah.show(desc) print(desc, "RESULT:", a)
def run(a, prt=sys.stdout): desc = 'QUICKSORT PARTITION' ah = ArrayHistory() j = _partition(a, lo=0, hi=len(a)-1, array_history=ah) ah.prt() ah.show(desc) print(desc, "RESULT:", ' '.join(str(e) for e in a))
def run(a, desc=None, prt=sys.stdout): ah = ArrayHistory() Sort(a, array_history=ah) if desc is None: desc = "INSERTION SORT" prt.write("{DESC} RESULT {A}\n".format(DESC=desc, A=' '.join(str(e) for e in a))) ah.prt() ah.show(desc)
def run(a, desc, prt=sys.stdout): ah = ArrayHistory() Sort(a, array_history=ah) ah.prt_intlvd() # After each merge, print the state of both a and aux #ah.show(desc) prt.write("{DESC} RESULT: {A}\n".format(DESC=desc, A=a))
def test_2(): # Keys are 'A' and 'B': a = [ {'B':1}, {'B':2}, {'B':3}, {'B':4}, {'B':5}, {'A':1} ] ah = ArrayHistory() Sort(a, array_history=ah) ah.show('SHELL')
def test_2(): # Keys are 'A' and 'B': a = [{'B': 1}, {'B': 2}, {'B': 3}, {'B': 4}, {'B': 5}, {'A': 1}] ah = ArrayHistory() Sort(a, array_history=ah) ah.show('SHELL')