-
-
Save igiu1988/6896294 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bubbleSort(list): | |
issorted = False | |
for i in range(0,len(list)): | |
issorted = True | |
# 在这一趟的比较中,如果发现这一趟的数列已经成有序状态,那就不用排了,并且是整个数列也都算排完了 | |
for j in range(0, len(list) - i - 1): | |
if list[j] > list[j+1]: | |
temp = list[j] | |
list[j] = list[j+1] | |
list[j + 1] = temp | |
issorted = False; | |
print "sort ",i, " " , list | |
if (issorted): | |
break; | |
list = [7, 4, 1, 3, 9, 2, 8] | |
bubbleSort(list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment