Skip to content

Commit ee58b59

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

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

data_structures/reversesort.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import List
22

3+
34
def reverse_selection_sort(arr: List[int]) -> List[int]:
45
"""
5-
Sorts an array using a modified selection sort algorithm where after finding
6+
Sorts an array using a modified selection sort algorithm where after finding
67
the minimum element, a subarray is reversed instead of swapping.
78
89
Parameters:
@@ -14,16 +15,16 @@ def reverse_selection_sort(arr: List[int]) -> List[int]:
1415
Example:
1516
>>> reverse_selection_sort([64, 25, 12, 22, 11])
1617
[11, 12, 22, 25, 64]
17-
18+
1819
>>> reverse_selection_sort([5, 4, 3, 2, 1])
1920
[1, 2, 3, 4, 5]
20-
21+
2122
>>> reverse_selection_sort([3, 1, 2])
2223
[1, 2, 3]
23-
24+
2425
>>> reverse_selection_sort([10])
2526
[10]
26-
27+
2728
>>> reverse_selection_sort([])
2829
[]
2930
"""
@@ -41,10 +42,12 @@ def reverse_selection_sort(arr: List[int]) -> List[int]:
4142
# If the minimum is not already at position i, reverse the subarray
4243
if min_index != i:
4344
# Reverse the subarray from position i to min_index
44-
arr[i:min_index + 1] = reversed(arr[i:min_index + 1])
45+
arr[i : min_index + 1] = reversed(arr[i : min_index + 1])
4546

4647
return arr
4748

49+
4850
if __name__ == "__main__":
4951
import doctest
52+
5053
doctest.testmod()

0 commit comments

Comments
 (0)