mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-31 06:33:44 +00:00
Optimised for loop iteration
This commit is contained in:
parent
c8e7a65475
commit
6a6349bdb0
|
@ -31,9 +31,9 @@ def bubble_sort(collection):
|
||||||
[-45, -5, -2]
|
[-45, -5, -2]
|
||||||
"""
|
"""
|
||||||
length = len(collection)
|
length = len(collection)
|
||||||
for i in range(length):
|
for i in range(length-1):
|
||||||
swapped = False
|
swapped = False
|
||||||
for j in range(length-1):
|
for j in range(length-1-i):
|
||||||
if collection[j] > collection[j+1]:
|
if collection[j] > collection[j+1]:
|
||||||
swapped = True
|
swapped = True
|
||||||
collection[j], collection[j+1] = collection[j+1], collection[j]
|
collection[j], collection[j+1] = collection[j+1], collection[j]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user