バブルソート(改)
http://www40.atwiki.jp/spellbound/pages/159.html
♥0 |
Line 34 |
Modified 2011-09-13 13:21:25 |
MIT License
archived:2017-03-20 05:48:14
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/uVWA
*/
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 = [3, 1, 4, 2];
for (var i:int = data.length - 1; i >= 1; i--)
{
var checked:Boolean = false;
for (var j:int = 0; j < i; j++)
{
// 値の比較
if (data[j] > data[j + 1])
{
// 値の入れ替え
var temp:int = data[j];
data[j] = data[j + 1];
data[j + 1] = temp;
checked = true;
}
}
// 1回も交換がなければループ終了
if (!checked) break;
}
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);
}
}
}