python-插入排序
插入排序
直接看代码吧, 这个和好理解, 反正我是看着和冒泡排序很像
#!/usr/bin/env python
# coding:utf-8
def insertSort(nums):
for i in range(len(nums)):
position = i
while position>0:
if nums[position-1]>nums[position]:
nums[position-1], nums[position] = nums[position], nums[position-1]
position -= 1
return nums
nums = [8,4,5,7,2,5,1]
print insertSort(nums)