Answers for "bubble sort in golang"

Go
0

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)
}
Posted by: Guest on July-05-2020

Browse Popular Code Answers by Language