2
3import "fmt"
4
5func merge(a []int, b []int) []int { 6
7 var r = make([]int, len(a) + len(b))
8 var i = 0
2
3import "fmt"
4
5func compAndSwap(arr []int, x int, y int, dir int) { 6 if((dir==1 && arr[x]>arr[y]) || (dir==0 && arr[x]<arr[y])) {
7 arr[x], arr[y] = arr[y], arr[x]
8 }
8 }
9}
10
11func bitonicMerge(arr []int, low int, count int, dir int) {12 if(count > 1) {
13 k := count/2
14 for i:=low; i<low+k; i++ {
20 }
21}
22
23func bitonicSort(arr []int, low int, count int, dir int) {24 if(count > 1) {
25 k := count/2
26 bitonicSort(arr, low, k, 1)
30 }
31}
32
33func sort(arr []int, n int, dir int) {34 bitonicSort(arr, 0, n, dir)
35}
36
If parameters of the same type lie consecutively, mention their type once at the end of the last parameter.
Unlike other languages, like C, where all parameters must be specified with types explicitly, it is not required to do so in Go. Combining the types is usually recommended for the sake of brevity.
func foo(a, b int, c, d int, e, f int, g int) {}
func foo(a, b, c, d, e, f, g int) {}