Skip to content

Commit 119da45

Browse files
committed
for better bubble sort
1 parent ab2161e commit 119da45

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

sorts/bubble_sort.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def bubble_sort(collection):
3030
[-45, -5, -2]
3131
"""
3232
length = len(collection)
33-
for i in range(length-1):
34-
for j in range(length-1):
33+
for i in range(length-1, -1, -1):#range(length-1, -1, -1)
34+
for j in range(i):#range(1, i)
3535
if collection[j] > collection[j+1]:
3636
collection[j], collection[j+1] = collection[j+1], collection[j]
3737

0 commit comments

Comments
 (0)