Skip to content

Commit 5c229b6

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

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

sorts/reverse_selection.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
python3 reverse_selection_sort.py
1111
"""
1212

13+
1314
def reverse_subarray(arr: list, start: int, end: int) -> None:
1415
"""
1516
Reverse a subarray in-place.
16-
17+
1718
:param arr: the array containing the subarray to be reversed
1819
:param start: the starting index of the subarray
1920
:param end: the ending index of the subarray
@@ -39,6 +40,7 @@ def reverse_subarray(arr: list, start: int, end: int) -> None:
3940
start += 1
4041
end -= 1
4142

43+
4244
def reverse_selection_sort(collection: list) -> list:
4345
"""
4446
A pure implementation of reverse selection sort algorithm in Python
@@ -70,14 +72,15 @@ def reverse_selection_sort(collection: list) -> list:
7072
for j in range(i + 1, n):
7173
if collection[j] < collection[min_idx]:
7274
min_idx = j
73-
75+
7476
# If the minimum is not at the start of the unsorted portion,
7577
# reverse the subarray to bring it to the front
7678
if min_idx != i:
7779
reverse_subarray(collection, i, min_idx)
78-
80+
7981
return collection
8082

83+
8184
if __name__ == "__main__":
8285
user_input = input("Enter numbers separated by a comma:\n").strip()
8386
unsorted = [int(item) for item in user_input.split(",")]

0 commit comments

Comments
 (0)