bubble sort in golang code example
Example: bubble sort in golang
package main
import (
"fmt"
"os"
"strconv"
)
func bubblesort() {
unsorted := os.Args[1:]
var data [5]int
for i, n := range unsorted {
value, err := strconv.Atoi(n)
data[i] = value
if err != nil {
data[i] = 0
}
}
for i := 0; i < len(data)-1; i++ {
for j := 0; j < len(data)-i-1; j++ {
if data[j] > data[j+1] {
data[j], data[j+1] = data[j+1], data[j]
}
}
}
fmt.Println(data)
}