MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Insertion

Function Insertion

sort/insertionsort.go:11–21  ·  view source on GitHub ↗
(arr []T)

Source from the content-addressed store, hash-verified

9import "github.com/TheAlgorithms/Go/constraints"
10
11func Insertion[T constraints.Ordered](arr []T) []T {
12 for currentIndex := 1; currentIndex < len(arr); currentIndex++ {
13 temporary := arr[currentIndex]
14 iterator := currentIndex
15 for ; iterator > 0 && arr[iterator-1] > temporary; iterator-- {
16 arr[iterator] = arr[iterator-1]
17 }
18 arr[iterator] = temporary
19 }
20 return arr
21}

Callers 2

insertionSortRunsFunction · 0.85
BucketFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected