3.Insertion Sort - Javascript
3.Insertion Sort - Javascript
const arr2 = [1,3,3,4,1,2];
function insertSort(items){
var len = items.length,
i,j,value;
for(i=0;i<len;i++){
value = items[i];
for(j=i-1; j>-1 && items[j]>value ;j--){
console.log("i=",i,"j=",j)
items[j+1] = items[j];
}
items[j+1] = value;
}
return items;
}
insertSort(arr2)
console.log(arr2)
Leave a comment