排序算法
一、冒泡算法
def bubleSort(list1): for i in range(0 , len(list1)): for j in range(1 , len(list1)-i): if list1[j] < list1[j+1]: list1[j] , list1[j+1] = list1[j+1] , list1[j] return list1
二、选择排序
def selectSort(arr): for i in range (len(arr)-1): minindex = i for j in range(i+1 , len(arr)): if arr[j]<arr[minindex]: minindex = j if i != minindex: arr[i], arr[minindex] = arr[minindex] , arr[i] return arr
三、交换排序
def StringSort(data): startindex = 0 endindex = 0 count = len(data) while startindex + endindex < count: if data[startindex] == '-': data[startindex] , data[count-endindex - 1] = data[count-endindex - 1],data[startindex] endindex +=1 else: startindex +=1 return data