4 ms·
Sleep sort is still my favourite - if you're sorting numbers, just spawn a new thread for each number, make it sleep that number of milliseconds and print out t
by gambiting 8y ago
Sleep sort is still my favourite - if you're sorting numbers, just spawn a new thread for each number, make it sleep that number of milliseconds and print out the number after waking up. After the largest number of milliseconds elapse, you have the sorted list of numbers nicely printed out.
- saagarjha 8y agoOf course, then you're just relying on your scheduler, which may or may not actually do the sort correctly.
- tinus_hn 8y agoThe scheduler doesn’t have a hard job if all but 1 thread is sleeping.
- benchaney 8y agoFiguring out which threads to wake up when is an equivalent problem to sorting. The kernel has to maintain a queue of threads sorted on their sleep times in order to implement the sleep syscall in the first place
- emilfihlman 8y agoIsn't sleep sort equivalent to gravity sort?
- bjoli 8y agoThen check if it's sorted. If it is not, double the sleep time increments to make it more tolerant to scheduler error.