Skip to content

Instantly share code, notes, and snippets.

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