Skip to content

Commit 6a6349b

Browse files
Optimised for loop iteration
1 parent c8e7a65 commit 6a6349b

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
@@ -31,9 +31,9 @@ def bubble_sort(collection):
3131
[-45, -5, -2]
3232
"""
3333
length = len(collection)
34-
for i in range(length):
34+
for i in range(length-1):
3535
swapped = False
36-
for j in range(length-1):
36+
for j in range(length-1-i):
3737
if collection[j] > collection[j+1]:
3838
swapped = True
3939
collection[j], collection[j+1] = collection[j+1], collection[j]

0 commit comments

Comments
 (0)