12.29下午主要讲的是简单的一维数组 和数组中利用冒泡排序排列大小
比如有 数字 0.5 20 1 5 4 3 6 利用冒泡排序按照从小到大的顺序排列
var arr=new Array() arr.push(0.5); // 另一种写法:arr[0]=0.5;arr[1]=20; // arr[2]=1;arr[3]=5; // arr[4]=4; arr[5]=3; arr[6]=6 arr.push(20); arr.push(1); arr.push(5); arr.push(4); arr.push(3); arr.push(6); var temp; for(i=0;i<arr.length;i++) { for(j=i+1; j<arr.length;j++) { if(arr[i]>arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } // 其中的一种写法:document.write(arr[i]) } for(var x in arr) //另一种写法 { document.write(arr[x]) }