for better bubble sort

This commit is contained in:
phlai 2016-09-11 17:51:34 +08:00
parent ab2161e470
commit 119da45c52

View File

@ -30,8 +30,8 @@ def bubble_sort(collection):
[-45, -5, -2]
"""
length = len(collection)
for i in range(length-1):
for j in range(length-1):
for i in range(length-1, -1, -1):#range(length-1, -1, -1)
for j in range(i):#range(1, i)
if collection[j] > collection[j+1]:
collection[j], collection[j+1] = collection[j+1], collection[j]