def count_sort(array): max_value = array[0] for i in array: if i > max_value: max_value = i count_array = [0] * (max_value + 1) for i in array: count_array[i] += 1 array.clear() for i in range(len(count_array)): for _ in range(count_array[i]): array.append(i) return array my_list = [5, 8, 6, 3, 9, 2, 1, 7] count_sort(my_list) print(my_list)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)