This content originally appeared on DEV Community and was authored by Riaj Ahmed
let arr=[57,2,3,12,43,23,23,43,56,98,03,77,23]
let insertion= a=>{
if(a.length<2){return a}
for(var i=0; i<a.length; i++){
//console.log(" value of i=",i, "move to ", a[i])
let temp
if(a[i]<a[i+1]){
//console.log( a[i], a[i+1])
temp=a[i]
a[i]=a[i+1]
a[i+1]=temp
i=i-2
}//else{console.log("nothing to do")}
}
return arr
}
console.log(insertion(arr))
This content originally appeared on DEV Community and was authored by Riaj Ahmed
Riaj Ahmed | Sciencx (2021-09-26T10:06:46+00:00) What kind of sorting method it is?. Retrieved from https://www.scien.cx/2021/09/26/what-kind-of-sorting-method-it-is/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.