Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Insertion sort implemented with Go
func insertionSort(data []int) []int {
for n := 1; n < len(data); n++ {
v := data[n]
for k:=n - 1; k >= 0; k-- {
if v < data[k] {
// swap
data[k+1] = data[k]
data[k] = v
}
}
}
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment