defShellSort(nums): gap = len(nums) // 2# 先确定一个间隔数(两两一组) # 按照 gap 分组 while gap > 0: # 对每组元素进行插入排序 for i inrange(gap, len(nums)): base = nums[i] j = i - gap while j >= 0and nums[j] > base: nums[j + gap] = nums[j] j -= gap nums[j+gap] = base # 缩小 gap 间隔 gap = gap // 2 return nums