标签:
function findMin(start,arr){
var iMin = 99999;
var iMinIndex = -1;
for(var i = start;i<arr.length;i++){
if(arr[i]<iMin){
iMin = arr[i];
iMinIndex = i;
}
}
return iMinIndex;
}
var arr = [12,5,8,7,-1,33,100,-101];
for(var i = 0;i<arr.length;i++){
//寻找当次最小的值的位置
var iMinIndex = findMin(i,arr);
var car;
car = arr[i];
arr[i] = arr[iMinIndex];
arr[iMinIndex] = car;
}
document.write(arr);
标签:
原文地址:http://www.cnblogs.com/liuocean/p/5572818.html