Skip to content

Instantly share code, notes, and snippets.

@dlion
Created September 15, 2014 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dlion/7e9c718c1ffa3b8863e4 to your computer and use it in GitHub Desktop.
Save dlion/7e9c718c1ffa3b8863e4 to your computer and use it in GitHub Desktop.
InsertionSort
package main
import "fmt"
func main() {
array := [6]int{5, 3, 1, 7, 2}
for k := 0; k <= 5; k++ {
m := k
for j := k + 1; j <= 5; j++ {
if array[j] < array[m] {
m = j
}
}
temp := array[m]
array[m] = array[k]
array[k] = temp
}
for i := 0; i < 6; i++ {
fmt.Printf("%d ", array[i])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment