Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Sleep Sort

from time import sleep
from threading import Timer

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

x = [3,2,4,7,3,6,9,1]
print sleep_sort(x)

#[1, 2, 3, 3, 4, 6, 7, 9]
Source by coderscat.com #
 
PREVIOUS NEXT
Tagged: #Sleep #Sort
ADD COMMENT
Topic
Name
5+1 =