コード例 #1
0
def visualize_comb_sort(lst, vis):
    start_time = time.perf_counter_ns()
    sort.comb_sort(lst, 1.3, vis)
    end_time = time.perf_counter_ns()

    vis.replay(0)
    vis.reset()

    print('Comb Sort')
    print(f'Time: {end_time - start_time:,}ns\n')
コード例 #2
0
def test_comb_sort(array):
    t0 = time.time()
    sort.comb_sort(array)
    t1 = time.time()
    print "Elapsed time (comb sort): " + elapsed_to_str(t0, t1) + " sec."
コード例 #3
0
ファイル: main.py プロジェクト: eric-ycw/sortpy
def main():
    win = gp.GraphWin('sortpy', WINDOW_X, WINDOW_Y, autoflush=False)
    win.setBackground(color=gp.color_rgb(43, 137, 164))

    print_logo()
    first_input = True
    while 1:
        clear_screen(win)
        ds = sort.generate_dataset(sort.DATA_NUM, repeat=False)
        bars = []
        draw_bars(ds, win, bars)
        sort.playback_list = []

        valid_command = False
        if first_input:
            command = input('Type help to view commands\n')
            first_input = False
        else:
            command = input('')
        while not valid_command:
            if command == 'help':
                print_header('Sorting algorithms')
                print_subheader('Bubble sorts')
                print_command('bubble', 'Bubble sort')
                print_command('cocktail', 'Cocktail shaker sort')
                print_command('comb', 'Comb sort')
                print_command('oddeven', 'Odd-even sort')
                print_subheader('Insertion sorts')
                print_command('insertion', 'Insertion sort')
                print_command('shell', 'Shellsort')
                print_command('gnome', 'Gnome sort')
                print_subheader('Divide and conquer')
                print_command('merge', 'Merge sort')
                print_command('quick', 'Quicksort')
                print_subheader('Other')
                print_command('selection', 'Selection sort')
                print_command('stooge', 'Stooge sort')

                print_header('Options')
                print_command('quit', 'Exit sortpy')

                print('\n')
                print('Click on the window after sorting finishes to select a new algorithm')
                command = input('\n')
            elif command == 'bubble':
                valid_command = True
            elif command == 'cocktail':
                valid_command = True
            elif command == 'comb':
                valid_command = True
            elif command == 'oddeven':
                valid_command = True
            elif command == 'insertion':
                valid_command = True
            elif command == 'shell':
                valid_command = True
            elif command == 'gnome':
                valid_command = True
            elif command == 'merge':
                valid_command = True
            elif command == 'quick':
                valid_command = True
            elif command == 'selection':
                valid_command = True
            elif command == 'stooge':
                valid_command = True
            elif command == 'quit':
                win.close()
                return
            else:
                print('Command not found - type help to view commands')
                command = input('\n')

        sort.playback_list.append(ds[:])
        if command == 'insertion':
            sort.insertion_sort(ds)
        elif command == 'bubble':
            sort.bubble_sort(ds)
        elif command == 'cocktail':
            sort.cocktail_sort(ds)
        elif command == 'selection':
            sort.selection_sort(ds)
        elif command == 'merge':
            sort.merge_sort(ds, 0, sort.DATA_NUM - 1)
        elif command == 'quick':
            sort.quick_sort(ds, 0, sort.DATA_NUM - 1)
        elif command == 'shell':
            sort.shell_sort(ds)
        elif command == 'gnome':
            sort.gnome_sort(ds)
        elif command == 'oddeven':
            sort.odd_even_sort(ds)
        elif command == 'comb':
            sort.comb_sort(ds)
        elif command == 'stooge':
            sort.stooge_sort(ds, 0, sort.DATA_NUM - 1)
        sort.playback_list = remove_duplicates(sort.playback_list)
        play_animation(ds, win, bars)
        win.getMouse()
コード例 #4
0
ファイル: example.py プロジェクト: EugeniyPetrov/sort
import sort

a = [71, 49, 69, 46, 43, 3, 73, 38, 77, 16, 65, 79, 80, 24, 2, 31, 55, 1, 82, 64]

b = a[:]
sort.merge_sort(b)
print b

b = a[:]
sort.comb_sort(b)
print b

b = a[:]
sort.shell_sort(b)
print b

b = a[:]
sort.shell_sort(b, None, 'shell')
print b

b = a[:]
sort.shell_sort(b, None, 'cuira')
print b

b = a[:]
sort.insertion_sort(b)
print b

b = a[:]
sort.coctail_sort(b)
print b
コード例 #5
0
    elif args[1] == "-me":
        sort.merge_sort(data)
    elif args[1] == "-qu":
        sort.quick_sort(data)
    elif args[1] == "-lsd":
        sort.lsd_radix_sort(data)
    elif args[1] == "-msd":
        sort.msd_radix_sort(data)
    elif args[1] == "-sh":
        sort.shell_sort(data)
    elif args[1] == "-sk":
        sort.shaker_sort(data)
    elif args[1] == "-he":
        sort.heap_sort(data)
    elif args[1] == "-cm":
        sort.comb_sort(data)
    elif args[1] == "-oe":
        sort.oddeven_sort(data)
    elif args[1] == "-gn":
        sort.gnome_sort(data)
    elif args[1] == "-gr":
        sort.gravity_sort(data)
    elif args[1] == "-st":
        print("[log] reset array")
        data = array.array('i', range(1, 30))
        mix_data(data)
        sort.stooge_sort(data)
    else:
        sys.exit("[error] select option")

    print("[log] {0}[s]".format(time.time() - start))