You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-algorithms/sorting/bubble_sort.go

26 lines
422 B
Go

package main
/*
* Bubble sort - http://en.wikipedia.org/wiki/Bubble_sort
*/
import "fmt"
import "github.com/0xAX/go-algorithms"
func main() {
arr := utils.RandArray(10)
fmt.Println("Initial array is:", arr)
fmt.Println("")
for i := 0; i < len(arr); i++ {
for j := 0; j < len(arr)-1-i; j++ {
if arr[j] > arr[j+1] {
arr[j],arr[j+1] = arr[j+1],arr[j]
}
}
}
fmt.Println("Sorted array is: ", arr)
}