Insertion Sort - Golang
package main
import "fmt"
func main() {
arr := []int{4, 1, 3, 2, 5}
result := insertionSort(arr)
fmt.Println(result)
}
func insertionSort(arr []int) []int {
for i, _ := range arr {
curr := arr[i]
j := i - 1
for j >= 0 && arr[j] > curr {
arr[j+1] = arr[j]
j -= 1
}
arr[j+1] = curr
}
return arr
}
The above program will print the following output:
[1 2 3 4 5]