Sleep sort
今話題のSleep sortをAS3で。
時々失敗します。
♥2 |
Line 35 |
Modified 2011-05-20 18:17:08 |
MIT License
archived:2017-03-10 09:29:14
ActionScript3 source code
/**
* Copyright saharan ( http://wonderfl.net/user/saharan )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jTPz
*/
package {
import flash.events.*;
import flash.utils.*;
import flash.text.TextField;
import flash.display.Sprite;
public class SleepSort extends Sprite {
private var trace:TextField;
public function SleepSort() {
initialize();
}
private function initialize():void {
trace = new TextField();
trace.wordWrap = true;
trace.width = 465;
trace.height = 465;
addChild(trace);
var numbers:Array = new Array();
var i:int;
for (i = 0; i < 200; i++) {
numbers[i] = i;
var flip:int = Math.random() * i;
var temp:uint = numbers[i];
numbers[i] = numbers[flip];
numbers[flip] = temp;
}
sort(numbers);
}
private function sort(numbers:Array):void {
for (var i:int = 0; i < numbers.length; i++) {
var number:uint = numbers[i] as uint;
setTimeout(trace.appendText, 500 + number * 100, number + " ");
}
}
}
}