Created
September 16, 2020 12:34
-
-
Save AleksandrChukhray/f529959fc065b233af26e27473255093 to your computer and use it in GitHub Desktop.
insertion sort algorithm
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
| function insertionSort(arr){ | |
| for(let i=1; i < arr.length; i++){ | |
| let key = arr[i]; | |
| let j = i - 1; | |
| while (j >= 0 && arr[j] > key){ | |
| arr[j+1] = arr[j]; | |
| j--; | |
| } | |
| arr[j+1] = key; | |
| } | |
| return arr; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment