Created
January 9, 2017 06:32
-
-
Save cipepser/fb4e64acc94d5b92a0227e898df99aa1 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
) | |
func InsertionSort(a []int) []int { | |
for i := 1; i < len(a); i++ { | |
for j := 0; j < i; j++ { | |
if a[i - j - 1] > a[i - j] { | |
a[i - j - 1], a[i - j] = a[i - j], a[i - j - 1] | |
} else { | |
break | |
} | |
} | |
} | |
return a | |
} | |
func main() { | |
a := []int{2, 4, 5, 1, 3} | |
fmt.Println(InsertionSort(a)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment