希尔排序——Python实现
一、排序思想
希尔排序思想请参见:https://www.cnblogs.com/luomeng/p/10592830.html
二、python实现
def shellSort(arr): """ python希尔排序 :param arr: 待排序列 step :步长值 """ step = len(arr) // 2 while step > 0: for rightIndex in range(step, len(arr)): while rightIndex >= step and arr[rightIndex] < arr[rightIndex - step]: arr[rightIndex - step], arr[rightIndex] = arr[rightIndex], arr[rightIndex - step] rightIndex -= step step //= 2 nums = [5, 6, 7, 2, 1, 65, 21, 22, 8, 0, 1] shellSort(nums) print(nums)