Skip to content

Instantly share code, notes, and snippets.

@felipernb
Created September 26, 2012 14:05
Show Gist options
  • Save felipernb/3788252 to your computer and use it in GitHub Desktop.
Save felipernb/3788252 to your computer and use it in GitHub Desktop.
Insertion Sort in Go
package sorting
func InsertionSort(a []int) []int {
for i := 1; i < len(a); i++ {
n := a[i]
j := i
for j > 0 && a[j-1] > n {
a[j] = a[j-1]
j--
}
a[j] = n
}
return a
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment