3 ms·
Stooge sort: stoogesort = (lo, hi) -> if VA.lt(hi, lo) VA.swap(lo, hi) if hi - lo > 1 third = Math.floor((hi - lo + 1)/3) stoogesor
by anonymoushn 15y ago
Stooge sort:
stoogesort = (lo, hi) ->
if VA.lt(hi, lo)
VA.swap(lo, hi)
if hi - lo > 1
third = Math.floor((hi - lo + 1)/3)
stoogesort(lo, hi-third)
stoogesort(lo+third, hi)
stoogesort(lo, hi-third)
stoogesort(0, VA.length-1)
It's probably best to run this on an array that's smaller than 100 numbers...