(arr []T)
| 11 | import "github.com/TheAlgorithms/Go/constraints" |
| 12 | |
| 13 | func BinaryInsertion[T constraints.Ordered](arr []T) []T { |
| 14 | for currentIndex := 1; currentIndex < len(arr); currentIndex++ { |
| 15 | temporary := arr[currentIndex] |
| 16 | low := 0 |
| 17 | high := currentIndex - 1 |
| 18 | |
| 19 | for low <= high { |
| 20 | mid := low + (high-low)/2 |
| 21 | if arr[mid] > temporary { |
| 22 | high = mid - 1 |
| 23 | } else { |
| 24 | low = mid + 1 |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | for itr := currentIndex; itr > low; itr-- { |
| 29 | arr[itr] = arr[itr-1] |
| 30 | } |
| 31 | |
| 32 | arr[low] = temporary |
| 33 | } |
| 34 | return arr |
| 35 | } |
nothing calls this directly
no outgoing calls
no test coverage detected