Created
September 26, 2011 21:56
-
-
Save robinhouston/1243524 to your computer and use it in GitHub Desktop.
A Sleep sort implementation for http://visualsort.appspot.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pos = [0 ... VA.length] | |
rpos = [0 ... VA.length] | |
swap = (i, j) -> | |
VA.swap i, j | |
tmp = rpos[j]; rpos[j] = rpos[i]; rpos[i] = tmp | |
pos[rpos[i]] = i; pos[rpos[j]] = j | |
j = 0 | |
for i in [0 ... VA.length] | |
v = VA.get(i) | |
do (v, i) -> | |
setTimeout -> | |
# Move the element that was originally in position i to position j | |
swap pos[i], j++ | |
VA.play() | |
, 100 * v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment