冒泡排序:
var a = [2,1,4,3,6,5];
for(var d = 0 ; d< a.length; d++){
for(var b = d+1; b < a.length; b++){
if (a [d] > a [b] );
var c = a [d];
a [d] = a [b];
a [b] = c ;
}
}
for(var e in a){
document.write(a [e] );
}
数组去重:
var arr = [9,9,1, 1, 2, 2, 3, 3, 4, 4, 4, 5, 5];
var arr2 = [];
for(var i = 0; i < arr.length; i++) {
var status = 0;
for(var j = 0; j < arr2.length; j++) {
if(arr[i] == arr2[j]) {
status = 1;
break;
}
}
if(status == 0) {
arr2.push(arr[i]);
}
}
for(var x in arr2) {
document.write(arr2[x]);
}