Created
October 15, 2018 11:09
-
-
Save sharmaabhinav/212f1141aa7f70a076192bbf1521c1cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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