Skip to content

Instantly share code, notes, and snippets.

@Xifeng2009
Last active September 14, 2018 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xifeng2009/e85dd50d0c51850b52bf133bb0d6e4eb to your computer and use it in GitHub Desktop.
Save Xifeng2009/e85dd50d0c51850b52bf133bb0d6e4eb to your computer and use it in GitHub Desktop.
冒泡排序
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