Skip to content

Commit cc6eb70

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

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

sorts/adaptive_merge_sort.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
python adaptive_merge_sort.py
1111
"""
1212

13+
1314
def adaptive_merge_sort(collection: list) -> list:
1415
"""
1516
Sorts a list using an adaptive merge sort algorithm.
@@ -32,13 +33,16 @@ def adaptive_merge_sort(collection: list) -> list:
3233
def find_run(collection: list, start: int) -> int:
3334
"""
3435
Detects and returns the length of a naturally occurring run starting from 'start'.
35-
36+
3637
:param collection: The list to detect runs in.
3738
:param start: The starting index for finding the run.
3839
:return: Length of the detected run.
3940
"""
4041
run_length = 1
41-
while start + run_length < len(collection) and collection[start + run_length - 1] <= collection[start + run_length]:
42+
while (
43+
start + run_length < len(collection)
44+
and collection[start + run_length - 1] <= collection[start + run_length]
45+
):
4246
run_length += 1
4347
return run_length
4448

@@ -65,7 +69,7 @@ def merge(left: list, right: list) -> list:
6569
# Step 1: Identify naturally occurring runs and store them in 'runs'
6670
while i < len(collection):
6771
run_length = find_run(collection, i)
68-
runs.append(collection[i:i + run_length])
72+
runs.append(collection[i : i + run_length])
6973
i += run_length
7074

7175
# Step 2: Iteratively merge runs until one sorted collection remains
@@ -83,6 +87,7 @@ def merge(left: list, right: list) -> list:
8387

8488
if __name__ == "__main__":
8589
import doctest
90+
8691
doctest.testmod()
8792
try:
8893
user_input = input("Enter numbers separated by a comma:\n").strip()

sorts/stalin_merge_sort.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
This is a pure Python implementation of the Stalin Sort algorithm.
3-
Stalin Sort removes any elements that are out of ascending order,
3+
Stalin Sort removes any elements that are out of ascending order,
44
leaving only a sorted subsequence of the original list.
55
66
For doctests run following command:
@@ -11,6 +11,7 @@
1111
python stalin_sort.py
1212
"""
1313

14+
1415
def stalin_sort(collection: list) -> list:
1516
"""
1617
Sorts a list by removing elements that are out of order, leaving a sorted subsequence.
@@ -40,6 +41,7 @@ def stalin_sort(collection: list) -> list:
4041

4142
if __name__ == "__main__":
4243
import doctest
44+
4345
doctest.testmod()
4446
try:
4547
user_input = input("Enter numbers separated by a comma:\n").strip()

0 commit comments

Comments
 (0)