Last active
June 15, 2020 04:29
-
-
Save educartoons/064fb8e9055a660aa9c2bfb00b989070 to your computer and use it in GitHub Desktop.
Sorting by Insertion implemented in Go
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
| func insertionSort(A []int) []int { | |
| for j := 0; j < len(A); j++ { | |
| var key = A[j] | |
| var i = j - 1 | |
| for i >= 0 && A[i] > key { | |
| A[i+1] = A[i] | |
| i = i - 1 | |
| } | |
| A[i+1] = key | |
| } | |
| return A | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment