package main import ( "fmt" ) func bubbleSort(a []int) { var temp int for j := 0; j < len(a); j++ { for i := 0; i < (len(a) - 1); i++ { if a[i] > a[i+1] { temp = a[i] a[i] = a[i+1] a[i+1] = temp } } } fmt.Println(temp) } func inputNums() []int { var input int var number int fmt.Scan(&input) s := make([]int, input) for i := 0; i < input; i++ { fmt.Scan(&number) s[i] = number } return s } func outputNums(b []int) { for i := 0; i < len(b); i++ { fmt.Print(b[i]) fmt.Print(" ") } } func main() { nums := inputNums() bubbleSort(nums) outputNums(nums) }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter