Last active
September 14, 2018 04:04
-
-
Save Xifeng2009/e85dd50d0c51850b52bf133bb0d6e4eb 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 bubble(bubbleList): | |
listLength = len(bubbleList) | |
while listLength > 0: | |
for i in range(listLength - 1): | |
if bubbleList[i] > bubbleList[i+1]: | |
bubbleList[i] = bubbleList[i] + bubbleList[i+1] | |
bubbleList[i+1] = bubbleList[i] - bubbleList[i+1] | |
bubbleList[i] = bubbleList[i] - bubbleList[i+1] | |
listLength -= 1 | |
print bubbleList |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment