Skip to content

Instantly share code, notes, and snippets.

@ls0f
Last active September 14, 2015 02:05
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 ls0f/0821c9f855aa13752360 to your computer and use it in GitHub Desktop.
Save ls0f/0821c9f855aa13752360 to your computer and use it in GitHub Desktop.
#coding:utf-8
def bubble_sort(sort_list):
length = len(sort_list)
while length > 1:
for i in range(1, length):
if sort_list[i] < sort_list[i-1]:
sort_list[i], sort_list[i-1] = sort_list[i-1],sort_list[i]
length -= 1
return sort_list
if __name__ == "__main__":
print bubble_sort([3,2,1,2,5,6,7])
print bubble_sort([1])
print bubble_sort([2,1])
print bubble_sort([2,1,78,0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment