Created
October 21, 2013 20:21
-
-
Save podviaznikov/7090293 to your computer and use it in GitHub Desktop.
Insertion sort implemented with 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(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