Merge pull request #27 from AlvinPH/bubble_sort_MD1

better bubble sort
This commit is contained in:
Chetan Kaushik 2016-09-11 22:17:19 +05:30 committed by GitHub
commit 753f4c55f3

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]