Insetion sort
A simple implementation of insertion sort algorithm in Go
package main
import (
"fmt"
)
func insertionSort(list []int){
for j :=1; j < len(list); j++ {
key := list[j]
i := j-1
for {
if i < 0 || list[i] < key {
break
}
list[i+1] = list[i]
i--
}
list[i+1] = key
}
}
func main() {
a := []int{2, 1, 3, 5, -4, -4, 6, -8, 7, 0}
// O(n^2)
insertionSort(a)
fmt.Println(a)
}