Skip to content

Instantly share code, notes, and snippets.

@sharmaabhinav
Created October 15, 2018 11:09
Show Gist options
  • Save sharmaabhinav/212f1141aa7f70a076192bbf1521c1cb to your computer and use it in GitHub Desktop.
Save sharmaabhinav/212f1141aa7f70a076192bbf1521c1cb to your computer and use it in GitHub Desktop.
var arr = [5,4,3,2,1]
function insertionSort (arr) {
if (arr.length === 0) {
return
}
start = 1
while(start <= arr.length-1) {
var index = start -1
var val = arr[start]
while(index >= 0 && arr[index] > val) {
arr[index + 1] = arr[index]
index -= 1
}
arr[index + 1] = val
start += 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment