//直接插入排序
function insert_sort(arr){ var len = arr.length; var result = []; result.push(arr[len-1]); for(var i = 0; i < len-1; i++){ var j = result.length; while(j > 0){ if(result[j-1] > arr[i]){ result[j] = result[j-1]; result[j-1] = arr[i]; j--; }else{ if(j == result.length){ result.push(arr[i]); } break; } } } alert(result); return result;}
时间: 2024-10-28 16:20:19