From bf82459589fc0827927151835e00971a9cc5ecf8 Mon Sep 17 00:00:00 2001 From: Yash Chandra Varma <71536409+yash509@users.noreply.github.com> Date: Tue, 11 Oct 2022 15:43:01 +0530 Subject: [PATCH 1/2] Added Code for Sleep Sort --- SleepSort.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 SleepSort.py diff --git a/SleepSort.py b/SleepSort.py new file mode 100644 index 000000000000..da5991ef693c --- /dev/null +++ b/SleepSort.py @@ -0,0 +1,22 @@ +from time import sleep +from threading import Timer + +def sleep_sort(l): + res = [] + def add1(x): + res.append(x) + mx = l[0] + for i in l: + if mx < i: + mx = i + Timer(i, add1, [i]).start() + sleep(mx+1) + return res + +l1 = [4,1,2,8,5] +print("Initial Array") +print(l1) + +print("Final Array is Arriving! Please wait..") +r = sleep_sort(l1) +print(r) From 28ac3fd02e633ece0aadf17ba434f3a55c6f6d58 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 11 Oct 2022 10:20:39 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- SleepSort.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/SleepSort.py b/SleepSort.py index da5991ef693c..1920bc2d46cd 100644 --- a/SleepSort.py +++ b/SleepSort.py @@ -1,19 +1,23 @@ -from time import sleep from threading import Timer +from time import sleep + def sleep_sort(l): res = [] + def add1(x): res.append(x) + mx = l[0] for i in l: if mx < i: mx = i Timer(i, add1, [i]).start() - sleep(mx+1) + sleep(mx + 1) return res -l1 = [4,1,2,8,5] + +l1 = [4, 1, 2, 8, 5] print("Initial Array") print(l1)