挿入ソート

by toilet7
http://www40.atwiki.jp/spellbound/pages/170.html
♥0 | Line 28 | Modified 2011-09-12 15:42:00 | MIT License
play

ActionScript3 source code

/**
 * Copyright toilet7 ( http://wonderfl.net/user/toilet7 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lkjw
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFormat;
    
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            
            var data:Array = [8, 4, 3, 7, 6];
                     
            for (var i:int = 1; i < data.length; i++)
            {
                var temp:int = data[i];
                
                 for (var j:int = i - 1; j >= 0 && data[j] > temp; j--)
                 {
                      data[j + 1] = data[j];
                 }
                 
                 data[j + 1] = temp;
            } 
            
            showResult(data);
        }
        
         private function showResult(...result:*):void
        {
             var tf:TextField = new TextField();
             tf.defaultTextFormat = new TextFormat("arial", 19);
             tf.text = result.toString();
             tf.autoSize = "left";
             addChild(tf);
        } 
    }
}