https://stackblitz.com/edit/js-bbrsjn
//insertionSort
function insertionSort(arry)
{
var total=arry.length;
var value,index;
for(var i=1;i<total;i++)
{
value=arry[i];
index=i;
while(index>0 && value<arry[index-1])
{
arry[index]=arry[index-1];
index=index-1;
}
arry[index]=value;
}
return arry;
}
var arry=[90,222,998,117,2];
insertionSort(arry);
console.log(arry);
Comments
Post a Comment