16 lines
264 B
Go
16 lines
264 B
Go
package sorting
|
|
|
|
type insertion struct{}
|
|
|
|
func (*insertion) Sort(items Sortable) {
|
|
len := items.Len()
|
|
for i := 1; i < len; i++ {
|
|
for j := i; j > 0 && items.Less(j, j-1); j-- {
|
|
items.Swap(j, j-1)
|
|
}
|
|
}
|
|
}
|
|
|
|
func NewInsertion() Sorter {
|
|
return &insertion{}
|
|
}
|