Skip to content

Instantly share code, notes, and snippets.

@antoniopicone
Created October 16, 2017 13:18
Show Gist options
  • Save antoniopicone/b751ecbf49ec6709577046440b5232ba to your computer and use it in GitHub Desktop.
Save antoniopicone/b751ecbf49ec6709577046440b5232ba to your computer and use it in GitHub Desktop.
var sequence = [3,4,1,2,6,5,8,7,9,0];
function insertionSort() {
for (var j=1;j<sequence.length;j++) {
var key = sequence[j];
var i=j-1;
while( i>=0 && sequence[i]>key ) {
sequence[i+1] = sequence[i];
i = i-1;
}
sequence[i+1]=key;
}
}
insertionSort();
console.log(sequence);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment