Bubble sort program

PHOTO EMBED

Tue Nov 15 2022 16:52:04 GMT+0000 (UTC)

Saved by @Plastikov #go

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)
}
content_copyCOPY