冒泡排序

<script type="text/javascript">
(function() {

//定义数组
var myArray = new Array(10, 8, 3, 5, 6, 7, 4, 6, 9);
for (var i = 1; i < myArray.length; i++) {
for (var j = 0; j < myArray.length - 1; j++) {

//判断大小替换位置的内容

if (myArray[j] > myArray[j + 1]) {
var temp = myArray[j];
myArray[j] = myArray[j + 1];
myArray[j + 1] = temp;
}
}


}
alert(myArray.join(','));
})();
</script>

posted on 2012-05-22 17:10  面包机  阅读(138)  评论(0编辑  收藏  举报

导航