def run_exercise2_2_2():
    array_to_be_sorted = common.random_int_list()

    def fn_sort(array):
        select_sort_e2_2_2(array, False)

    common.test_sort(array_to_be_sorted, fn_sort)
def run_exercise2_1_2():
    array_to_be_sorted = common.random_int_list()

    def fn_sort(array):
        insert_sort_e2_1_2(array, True)

    common.test_sort(array_to_be_sorted, fn_sort)
def run_exercise_2_3_4():
    array_to_be_sorted = common.random_int_list()

    def fn_sort(array):
        insert_sort_recursive_e2_3_4(array_to_be_sorted, len(array) - 1, True)

    common.test_sort(array_to_be_sorted, fn_sort)
def run_exercise_2_3_2():
    array_to_be_sorted = common.random_int_list()

    def fn_sort(array):
        merge_sort_e2_3_2(array, 0, len(array) - 1)

    common.test_sort(array_to_be_sorted, fn_sort)
def run_exercise_2_3_6():
    array_to_sort = range(10000, 1, -1)
    # array_to_sort = range(1, 10000, 1)
    # array_to_sort = common.random_int_list(1, 100000, 10000)
    common.test_sort(list(array_to_sort),
                     insert_sort_with_binary_search_e2_3_6, False)

    def fn_merge_sort(array):
        merge_sort_e2_3_2(array, 0, len(array) - 1)

    common.test_sort(list(array_to_sort), fn_merge_sort, False)
        else:
            array[index] = array_right[index_right]
            index_right = index_right + 1


def merge_sort(array, p, r):  # P31, 中文版19页
    if p < r:
        q = int((r+p)/2)
        merge_sort(array, p, q)
        merge_sort(array, q+1, r)
        _merge(array, p, q, r)


if __name__ == '__main__':
    array_to_sort = common.random_int_list(1, 100000, 10000)
    common.test_sort(list(array_to_sort), insert_sort, False)

    def fn_merge_sort(array):
        merge_sort(array, 0, len(array) - 1)

    common.test_sort(list(array_to_sort), fn_merge_sort, False)

    # array_to_merge = [1,3,5,7,2,4,6,8]
    # _merge(array_to_merge,0,3,7)
    # print(array_to_merge)