Created
August 9, 2022 14:35
-
-
Save tsyber1an/594ff022bf878e91080e07de33a64fe9 to your computer and use it in GitHub Desktop.
Revisions
-
tsyber1an created this gist
Aug 9, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ package main import "fmt" func handler[arg int64 | float32](input arg) { fmt.Println(input) } type Number in qzzzterface { int8 | int16 | int32 | int64 | float32 | float64 } func BubbleSort[N Number](input []N) []N { n := len(input) swapped := true for swapped { swapped = false for i := 0; i < n-1; i++ { if input[i] > input[i+1] { input[i], input[i+1] = input[i+1], input[i] swapped = true } } } return input } func main() { var a int64 = 160 var b float32 = 1.3 handler(a) handler(b) list := []int32{4,3,1, 5,6} lstFloat := []float32{4.3, 3.2, 1.3, 5.1, 6.9} sorted := BubbleSort(list) fmt.Println(sorted) sortedFloats := BubbleSort(lstFloat) fmt.Println(sortedFloats) }