- 博客(8)
- 收藏
- 关注
原创 归并排序(二路归并) Python实现
def Merge(nums, low, mid, high): res = [] i = low j = mid+1 while i<=mid and j<=high: if nums[i]<=nums[j]: res.append(nums[i]) i += 1 e...
2020-03-02 00:43:00
585
1
原创 堆排序(最大堆) Python实现
def AdjustUp(nums, k, n): #用于插入新值 i = 2*k temp = nums[k] while i>0 and nums[i]<temp: nums[k] = nums[i] k = i i /= 2 nums[k] = tempdef AdjustD...
2020-03-01 22:52:33
180
原创 简单选择排序 Python实现
def SelectSort(nums): n = len(nums) for i in range(0, n-1): min_pos = i for j in range(i+1, n): if nums[min_pos]>nums[j]: min_pos = j if ...
2020-03-01 19:05:09
160
原创 快速排序 Python实现
##nums is the list including numbers##def Partition(nums, left, right): privot = nums[left] while left<right: while left<right and nums[right]>=privot: right -= 1...
2020-03-01 17:58:58
81
原创 冒泡排序 Python实现
def BubbleSort(nums): n = len(nums) for i in range(n-1, 0, -1): for j in range(1, i+1): if nums[j]<nums[j-1]: temp = nums[j] nums[j] = nu...
2020-03-01 17:33:15
70
原创 希尔排序 Python实现
##nums is the list including numbers##def ShellSort(nums): n = len(nums) slide = n/2 while slide>=1: index = slide while index<n: if nums[index]<nums[...
2020-03-01 17:24:11
98
原创 折半插入排序 Python实现
##nums is the list including numbers##def BinaryInsertSort(nums): n = len(nums) if n<=1: return nums for i in range(1, n): if nums[i]<nums[i-1]: temp = n...
2020-03-01 00:28:11
402
原创 直接插入排序 Python实现
##nums is the list including numbers##def insertSort(nums): n = len(nums) if n<=1: return nums for i in range(1, n): if nums[i]<nums[i-1]: j = i - 1 ...
2020-02-29 23:40:20
174
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人