We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0bcdd37 commit 2c462b1Copy full SHA for 2c462b1
sorts/sleep_sort.py
@@ -1,13 +1,14 @@
1
import threading
2
import time
3
4
+
5
def sleep_sort(arr):
6
"""
7
Sorts a list of positive integers using Sleep Sort.
-
8
9
Args:
10
arr (list[int]): List of positive integers to sort.
11
12
Returns:
13
list[int]: Sorted list in ascending order.
14
@@ -19,17 +20,18 @@ def sleeper(x):
19
20
result.append(x)
21
22
threads = [threading.Thread(target=sleeper, args=(num,)) for num in arr]
23
24
# Start all threads
25
for t in threads:
26
t.start()
27
28
# Wait for all threads to finish
29
30
t.join()
31
32
return result
33
34
35
# Example Usage
36
if __name__ == "__main__":
37
numbers = [4, 1, 3, 2]
0 commit comments