summaryrefslogtreecommitdiff
path: root/sort/insertion.go
blob: 62dcf329c52eaf162d21d0902bcfdaad6ff823db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package sort

import (
	"codeberg.org/snonux/algorithms/ds"
)

func Insertion(a ds.ArrayList) ds.ArrayList {
	for i, _ := range a {
		for j := i; j > 0; j-- {
			if a[j] > a[j-1] {
				break
			}
			a.Swap(j, j-1)
		}
	}

	return a
}