冒泡排序怎么写?
冒泡排序怎么写?
冒泡排序怎么写?
2016-06-02
<script type="text/javascript">
var temp=0, i, j;
var arr = [2,5,4,3];
for (i = 0; i < arr.length; i++)
{
//j必须从i的下一个位置数开始
for (j = i+1; j < arr.length-i; j++)
{
if (arr[i] >arr[j + 1])
{
temp = arr[i];
arr[i] = arr[j + 1];
arr[j + 1] = temp;
}
else { arr[i] = arr[i];}
}
document.write(arr[i]);
}
</script>举报