插入排序算法
def getsort1(arr):
for i in range(0,len(arr)):
for j in range(i,len(arr)):
if arr[i] > arr[j]:
arr[i],arr[j] = arr[j],arr[i]
else:
pass
print arr
print arr
arr1 = [20,11,13,5,14,4,61,18,9,17,25,22]
print arr1
print "######################################"
getsort1(arr1)
Paste_Image.png
冒泡排序算法
def getsort2(arr):
for i in range(0,len(arr)-1):
for j in range(0,len(arr)-1-i):
if arr[j] > arr[j+1]:
arr[j],arr[j+1] = arr[j+1],arr[j]
else:
pass
print arr
print arr
arr1 = [20,11,13,5,14,4,61,18,9,17,25,22]
print arr1
print "######################################"
getsort2(arr1)
Paste_Image.png
网友评论