Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions sorts/sleep_sort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from threading import Timer
from time import sleep

""" In sleep sort, the thread having
the least amount of sleeping time
wakes up first and the number gets
printed and hence list is sorted"""


def sleep_sort(values):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file sorts/sleep_sort.py, please provide doctest for the function sleep_sort

Please provide return type hint for the function: sleep_sort. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: values

sleep_sort.result = []
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file sorts/sleep_sort.py, please provide doctest for the function sleep_sort

Please provide return type hint for the function: sleep_sort. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: values


def add1(x):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file sorts/sleep_sort.py, please provide doctest for the function add1

Please provide return type hint for the function: add1. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: x

Please provide descriptive name for the parameter: x

sleep_sort.result.append(x)

mx = values[0]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file sorts/sleep_sort.py, please provide doctest for the function add1

Please provide return type hint for the function: add1. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: x

Please provide descriptive name for the parameter: x

for v in values:
if mx < v:
mx = v
Timer(v, add1, [v]).start()
sleep(mx + 1)
return sleep_sort.result


if __name__ == "__main__":
x = [3, 2, 4, 7, 3, 6, 9, 1]
print(sleep_sort(x))
# [1, 2, 3, 3, 4, 6, 7, 9]