希尔排序思想请参见: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)


相关文章:

  • 2022-01-06
  • 2021-08-09
  • 2022-01-06
  • 2021-12-16
  • 2021-11-01
  • 2022-12-23
猜你喜欢
  • 2021-06-18
  • 2021-07-20
  • 2021-12-05
  • 2022-12-23
  • 2021-10-19
  • 2021-07-22
相关资源
相似解决方案