from data import DataSeq def CombSort(ds): Length = ds.length D = int(Length / 1.3) while D: for i in range(Length): for j in range(i + D, Length, D): if ds.data[j - D] > ds.data[j]: ds.Swap(j - D, j) D = int(D / 1.3) if __name__ == "__main__": ds = DataSeq(64, repeatition=True) ds.Visualize() ds.StartTimer() CombSort(ds) ds.StopTimer() ds.SetTimeInterval(0) ds.Visualize()
i += 1 while j <= RightEnd: ds.SetVal(k, tmpData[j]) k += 1 j += 1 def Sort(ds, L, RightEnd, time_interval): # import ipdb; ipdb.set_trace() if RightEnd > L: mid = (L + RightEnd) // 2 Sort(ds, L, mid, time_interval) Sort(ds, mid + 1, RightEnd, time_interval) Merge(ds, L, mid + 1, RightEnd, time_interval) def MergeSort(ds, time_interval=1): assert isinstance(ds, DataSeq), "Type Error" Length = ds.length Sort(ds, 0, Length - 1, time_interval) if __name__ == "__main__": ds = DataSeq(64) ds.Visualize() ds.StartTimer() MergeSort(ds) ds.StopTimer() ds.SetTimeInterval(0) ds.Visualize()
parser.add_argument('-i', '--interval', type=int, default=1) parser.add_argument( '-t', '--sort-type', type=str, default='Bubble', choices=["Bubble", "Insertion", "Merge", "Selection", "Radix", "Heap"]) args = parser.parse_args() if __name__ == "__main__": MAXLENGTH = 10000 Length = args.length if args.length < MAXLENGTH else MAXLENGTH Interval = args.interval SortType = args.sort_type try: SortMethod = eval(SortType) except: print("Busca nao encontrada %s !" % SortType) exit() ds = DataSeq(Length, time_interval=Interval, sort_title=SortType) ds.Visualize() ds.StartTimer() SortMethod(ds) ds.StopTimer() #tempo da janela gráfica time.sleep(3)
parser.add_argument('-n', '--no-record', action='store_true') args = parser.parse_args() if __name__ == "__main__": MAXLENGTH = 1000 Length = args.length if args.length < MAXLENGTH else MAXLENGTH Interval = args.interval SortType = args.sort_type Resampling = args.resample Sparse = args.sparse NoRecord = args.no_record try: SortMethod = eval(SortType) except: print("Sort Type Not Found! Please Check if %s Exists or Not!" % SortType) exit() ds = DataSeq(Length, time_interval=Interval, sort_title=SortType, is_resampling=Resampling, is_sparse=Sparse, record=not NoRecord) ds.Visualize() ds.StartTimer() SortMethod(ds) ds.StopTimer() ds.SetTimeInterval(0) ds.Visualize()
args = parse_args() MAXLENGTH = 1000 Length = args.length if args.length < MAXLENGTH else MAXLENGTH Interval = args.interval SortType = args.sort_type Resampling = args.resample Sparse = args.sparse NoRecord = args.no_record NoSound = args.silent sound_interval = args.sound_interval try: SortMethod = eval(SortType) except: print("Sort Type Not Found! Please Check if %s Exists or Not!" % SortType) exit() if not NoSound and sound_interval * 10 < Interval: print("UserWarning: sound interval too small") ds = DataSeq(Length, time_interval=Interval, sort_title=SortType, is_resampling=Resampling, is_sparse=Sparse, record=not NoRecord, sound=not NoSound, sound_interval=sound_interval) ds.StartTimer() SortMethod(ds) ds.StopTimer() ds.Hold()
import argparse parser = argparse.ArgumentParser(description="Sort Visulization") parser.add_argument('-l', '--length', type=int, default=64) parser.add_argument('-i', '--interval', type=int, default=1) parser.add_argument('-t', '--sort-type', type=str, default='BubbleSort') parser.add_argument('-r', '--repetition', action='store_true') args = parser.parse_args() if __name__ == "__main__": MAXLENGTH = 1000 Length = args.length if args.length < MAXLENGTH else MAXLENGTH Interval = args.interval SortType = args.sort_type Repetition = args.repetition try: SortMethod = eval(SortType) except: print("Sort Type Not Found!") exit() ds = DataSeq(Length, time_interval=Interval, sort_title=SortType, repeatition=Repetition) ds.Visualize() ds.StartTimer() SortMethod(ds) ds.StopTimer() ds.SetTimeInterval(0) ds.Visualize()