Bubble Sort:
The next two numbers are compared first, i.e. li[0] and li[1], and if they are not greater than the relationship, proceed to li[1] and li[2] comparison, and then each scan gets a new list as follows:
###### #冒泡排序 ###### #li = [11,22,32,344,3,] for I in range (Len (LI)-1): Xin = (Li[i]) Kai = li[i+1] If Li[i] >li[i+1]: temp = li[i] li[i] = li[i+1] Li[i+1]=tempprint (LI) for i in Ran GE (Len (li)-2): Xin = (Li[i]) Kai = li[i+1] If li[i] >li[i+1]: temp = li[i] li[i] = li[i+1] Li[i+1]=tempprint (LI) for I in Range (Len (LI)-3): Xin = (Li[i]) Kai = li[i+1] If li[i] >li[i+1]: temp = Li[i] li[i] = li[i+1] Li[i+1]=tempprint (LI) for I in Range (Len (LI)-3): Xin = (Li[i]) Kai = li[i+1] If Li[i] >li[i+1]: temp = li[i] li[i] = li[i+1] Li[i+1]=tempprint (LI) Execution result: [11, 22, 32, 3, 344][11, 22, 3, 32, 344][11, 3, 22, 32, 344][3, 11, 22, 32, 344] bubble sort for j in range (Len (LI)): #j: All-in-a For I in range (Len (LI)-1) : if Li[i] >li[i+1]: temp = li[i] li[i] = li[i+1] Li[i+1]=tempprint (LI) Execution result [3, 11, 22, 32, 344]
Python bubble sort