冒泡排序
<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>
代码改变世界,记录知识.