Skip to content

Commit 64d8a1b

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent af520e8 commit 64d8a1b

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

sorts/bubble_sort.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
from typing import Any
22

3+
34
def bubble_sort(collection: list[Any]) -> list[Any]:
45
"""Non-optimised O(n^2) implementation of bubble sort algorithm (iterative)"""
56
n = len(collection)
67
for i in range(n):
7-
for j in range(n-1-i): # number of pairs
8-
if collection[j] > collection[j+1]:
9-
collection[j], collection[j+1] = collection[j+1], collection[j]
8+
for j in range(n - 1 - i): # number of pairs
9+
if collection[j] > collection[j + 1]:
10+
collection[j], collection[j + 1] = collection[j + 1], collection[j]
1011
return collection
1112

13+
1214
def bubble_sort_iterative(collection: list[Any]) -> list[Any]:
1315
"""Pure implementation of bubble sort algorithm in Python
1416
@@ -53,7 +55,7 @@ def bubble_sort_iterative(collection: list[Any]) -> list[Any]:
5355
length = len(collection)
5456
for i in reversed(range(length)):
5557
swapped = False
56-
for j in range(i): # number of pairs
58+
for j in range(i): # number of pairs
5759
if collection[j] > collection[j + 1]:
5860
swapped = True
5961
collection[j], collection[j + 1] = collection[j + 1], collection[j]

0 commit comments

Comments
 (0)