We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
sorts/bubble_sort.py
1 parent f05585a commit dc64bc4Copy full SHA for dc64bc4
sorts/bubble_sort.py
@@ -1,4 +1,7 @@
1
-def bubble_sort(collection):
+from typing import Any
2
+
3
4
+def bubble_sort(collection: list[Any]) -> list[Any]:
5
"""Pure implementation of bubble sort algorithm in Python
6
7
:param collection: some mutable ordered collection with heterogeneous
@@ -28,9 +31,9 @@ def bubble_sort(collection):
28
31
True
29
32
"""
30
33
length = len(collection)
- for i in range(length - 1):
34
+ for i in reversed(range(length)):
35
swapped = False
- for j in range(length - 1 - i):
36
+ for j in range(i):
37
if collection[j] > collection[j + 1]:
38
swapped = True
39
collection[j], collection[j + 1] = collection[j + 1], collection[j]
0 commit comments