Skip to content

Commit b309ed0

Browse files
committed
reformatting smooth sort algorithm
1 parent 87ac4b9 commit b309ed0

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

sorts/smooth_sort.py

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
"""
2+
This is a pure Python implementation of the smoothSort algorithm
3+
Smooth Sort is an algorithm combine the concept of heap sort and the
4+
concept of merge sort It was designed by Edsger W. Dijkstra
5+
and later refined by Steven J. Ross.
6+
7+
More info on: https://en.wikipedia.org/wiki/Smoothsort
8+
9+
For doctests run following command:
10+
python -m doctest -v smooth_sort.py
11+
or
12+
python3 -m doctest -v smooth_sort.py
13+
For manual testing run:
14+
python bogo_sort.py
15+
"""
16+
17+
118
def smooth_sort(unsorted):
219
"""
320
Pure implementation of the smooth sort algorithm using Leonardo numbers in Python
@@ -85,11 +102,17 @@ def heapify(start, end):
85102

86103

87104
if __name__ == "__main__":
88-
user_input = input(
89-
"Enter numbers separated by a comma (or press Enter to exit):\n"
90-
).strip()
91-
if not user_input:
92-
print(smooth_sort([]))
93-
else:
94-
unsorted = [int(item) for item in user_input.split(",")]
95-
print(smooth_sort(unsorted))
105+
import doctest
106+
107+
doctest.testmod()
108+
try:
109+
user_input = input(
110+
"Enter numbers separated by a comma (or press Enter to exit):\n"
111+
).strip()
112+
if not user_input:
113+
print(smooth_sort([]))
114+
else:
115+
unsorted = [int(item) for item in user_input.split(",")]
116+
print(smooth_sort(unsorted))
117+
except ValueError:
118+
print("Invalid input. Please enter valid integers separated by commas.")

0 commit comments

Comments
 (0)