Created
June 23, 2020 22:52
-
-
Save educartoons/3d1997ce56c059b09785f4535227e4ad to your computer and use it in GitHub Desktop.
Implementation of Insertion Sort in Go
This file contains 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