Пример #1
0
            array = counting_sort(array, digit)
            array = seperate(array, digit)

            for i in array:
                output += radix_sort(i, msd=True, digit=digit - 1)
        else:
            output = array

        return output

    else:
        return radix_sort(array, lsd=True)  #LSD by default


if __name__ == "__main__":
    import os, sys  #import shuffler from parent directory
    dir_path = os.path.dirname(os.path.realpath(__file__))
    parent_dir_path = os.path.abspath(os.path.join(dir_path, os.pardir))
    sys.path.insert(0, parent_dir_path)
    from shuffler import random_sequence

    print("RADIX SORT")
    shuffled_array = random_sequence(0, 1000)

    print(shuffled_array, "\n")

    print("LSD")
    print(radix_sort(shuffled_array, lsd=True), "\n")

    print("MSD")
    print(radix_sort(shuffled_array, msd=True, digit=None))
                else:
                    changed = []
                draw_graph(screen,
                           array,
                           current=section + 1,
                           changed=[section + 1])
        else:
            array[
                section +
                1] = comparator  # if loop wasn't broken, insert comparator in the right spot
            if section + 1 >= 0:
                changed = [section + 1]
            else:
                changed = []
            draw_graph(screen, array, current=section + 1, changed=changed)

    return array


numVals = 100

shuffled_array = random_sequence(0, min(numVals, screen.winfo_width()))

draw_graph(screen, shuffled_array)

sorted_array = insertion_sort(shuffled_array)

draw_graph(screen, sorted_array, finished=True)

screen.mainloop()