#小练习 冒泡排序

alist=['deff', 'ABC','xtazz','Abc','abc',]



#len(alist)=5


for i in range(len(alist)-1): # i = 0 1 2 3


    for j in  range(len(alist)-i-1):


        if alist[j] > alist[j+1]:


            alist[j],alist[j+1] =alist[j+1],alist[j]


print alist


 趟数      该趟比较次数

 1                len -1

 2                len -2

 3                len -3

 ..                 ....

 n-1              1

你可能感兴趣的:(#小练习 冒泡排序)