10 examples of 'insert sort' in Go

Every line of 'insert sort' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
55func insertionSort(data Sorter, a, b int) {
56 for i := a + 1; i < b; i++ {
57 for j := i; j > a && data.Less(j, j-1); j-- {
58 data.Swap(j, j-1)
59 }
60 }
61}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

27func insertionSortAsc(data []uint16, a, b int) {
28 var j int
29 for i := a + 1; i < b; i++ {
30 for j = i; j > a && data[j] < data[j-1]; j-- {
31 data[j], data[j-1] = data[j-1], data[j]
32 }
33 }
34}
27func insertionSortAsc(data []int16, a, b int) {
28 var j int
29 for i := a + 1; i < b; i++ {
30 for j = i; j > a && data[j] < data[j-1]; j-- {
31 data[j], data[j-1] = data[j-1], data[j]
32 }
33 }
34}
27func insertionSortAsc(data []float64, a, b int) {
28 var j int
29 for i := a + 1; i < b; i++ {
30 for j = i; j > a && data[j] < data[j-1]; j-- {
31 data[j], data[j-1] = data[j-1], data[j]
32 }
33 }
34}
799func (p *sortDecimalAscOp) insertionSort(a, b int) {
800 for i := a + 1; i < b; i++ {
801 for j := i; j > a && p.Less(j, j-1); j-- {
802 p.Swap(j, j-1)
803 }
804 }
805}
45func (p *sort_TYPE_DIR_HANDLES_NULLSOp) insertionSort(a, b int) {
46 for i := a + 1; i < b; i++ {
47 for j := i; j > a && p.Less(j, j-1); j-- {
48 p.Swap(j, j-1)
49 }
50 }
51}
1754func (p *sortInt16DescOp) insertionSort(a, b int) {
1755 for i := a + 1; i < b; i++ {
1756 for j := i; j > a && p.Less(j, j-1); j-- {
1757 p.Swap(j, j-1)
1758 }
1759 }
1760}
2709func (p *sortFloat32AscOp) insertionSort(a, b int) {
2710 for i := a + 1; i < b; i++ {
2711 for j := i; j > a && p.Less(j, j-1); j-- {
2712 p.Swap(j, j-1)
2713 }
2714 }
2715}
60func insertSort(orders []sessionOrder, so sessionOrder, direction int) []sessionOrder {
61 index := sort.Search(len(orders), func(i int) bool {
62 cmp := so.getPrice().Cmp(orders[i].getPrice()) * direction
63 if cmp == 0 {
64 cmp = CmpTime(so.time, orders[i].time)
65 }
66 return cmp >= 0
67 })
68
69 return append(orders[:index], append([]sessionOrder{so}, orders[index:]...)...)
70}
22func sort(a, b, c int) (int, int, int) {
23 if c < a {
24 a, c = c, a
25 }
26 if b < a {
27 a, b = b, a
28 }
29 if c < b {
30 b, c = c, b
31 }
32 return a, b, c
33}

Related snippets