Skip to content

Commit 067a9b5

Browse files
mvhbcclauss
authored andcommitted
adding input option and increasing the number of doctest (TheAlgorithms#1281)
* adding input option and incresing the number of doctest * mixing positive and negative numbers in the same test case
1 parent 9cc9f67 commit 067a9b5

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sorts/stooge_sort.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
def stooge_sort(arr):
22
"""
3-
>>> arr = [2, 4, 5, 3, 1]
4-
>>> stooge_sort(arr)
5-
>>> print(arr)
6-
[1, 2, 3, 4, 5]
3+
Examples:
4+
>>> stooge_sort([18.1, 0, -7.1, -1, 2, 2])
5+
[-7.1, -1, 0, 2, 2, 18.1]
6+
7+
>>> stooge_sort([])
8+
[]
79
"""
810
stooge(arr, 0, len(arr) - 1)
11+
return arr
912

1013

1114
def stooge(arr, i, h):
@@ -29,3 +32,8 @@ def stooge(arr, i, h):
2932

3033
# Recursively sort first 2/3 elements
3134
stooge(arr, i, (h - t))
35+
36+
if __name__ == "__main__":
37+
user_input = input("Enter numbers separated by a comma:\n").strip()
38+
unsorted = [int(item) for item in user_input.split(",")]
39+
print(stooge_sort(unsorted))

0 commit comments

Comments
 (0)