Insertion Sort
Implmentation
Let's implment the insertion sort:
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
let index = 0;
while(index < array.length) {
const element = array[index];
for(let r=index-1; r>0; r--) {
const tempElement = array[r];
if(element < tempElement) {
array[r+1] = tempElement;
} else if (element >= tempElement) {
array[r+1] = element;
break;
}
}
index++;
}