Bubble sort in Golang
package main import "fmt" func sorting (a []int) []int { for i:= 0; i<len(a)-1; i++{ for j:=0; j<len(a)-i-1; j++ { if a[j] > a[j+1] { //storing actual value a "temp" variable temp:= a[j] a[j] = a[j+1] a[j+1] = temp } } } return a } func main() { myArray := []int{9,8,7,6,5,4,3,2,1,0} fmt.Println(myArray) sorting(myArray) fmt.Println(myArray) }