Python十大排序算法_python教程

代码如下: 快排
 

'''
几乎是我们学习排序入门算法了,两次遍历,时间复杂度较高n*n,稳定排序
'''
def bubbleSort(tmpList):
    for i in range(len(tmpList)-1):
        for j in range(len(tmpList)-1,i,-1):
            if tmpList[j-1] > tmpList[j]:
                tmpList[j-1],tmpList[j] = tmpList[j],tmpList[j-1]
    print(tmpList)
bubbleSort([9,8,7,6,5,4,3,2,1])


'''
选择排序:思想就是 当当前数跟后面所以对比,然后找到最小的。这两个点进行交换。
331 -> 133  不稳定排序 时间复杂度n*n
'''
def selectSort(tmpList):
    for i in range(len(tmpList) - 1):
        minIndex = i
        for j