Inserttion sort
It is a simple sorting algorithm that work simliar to the way you sort palying cards in your hand. split into sorted and an unsorted pat
pick a number num:=index[n], compare (index[n~1],and index[n~1] has sorted.).
Loop compare
if index[n] < index[n-1], then index[n] =index[n-1]. and index[n-1] compare index[n-2].
go to comapre to compare, until index[n] > index[n-1]
Finally, swap(num,n)
Code
func insertionSort(a []int) []int {
for i := 1; i < len(a); i++ {
tmp := a[i]
j := i
// 0~j-1 has sorted, j~len(a)-1 is unsorted
for j > 0 && tmp < a[j-1] {
a[j] = a[j-1]
j--
}
if j != i {
a[j] = tmp
}
}
return a
}