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_exercise_2_3_7(): array_to_search = common.random_int_list(1, 100000, 10000) # array_to_search.append(array_to_search[300]) has_same_elements = merge_sort_as_find_same_elements( array_to_search, 0, len(array_to_search) - 1) print(has_same_elements)
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)
index_left = index_left + 1 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)