2
0
mirror of https://github.com/0xAX/go-algorithms synced 2024-11-11 19:10:39 +00:00
go-algorithms/sorting/bubble_sort.go

30 lines
558 B
Go
Raw Normal View History

2014-06-21 16:59:23 +00:00
package main
/*
2014-06-22 15:00:00 +00:00
* Bubble sort - http://en.wikipedia.org/wiki/Bubble_sort
2014-06-21 16:59:23 +00:00
*/
import "fmt"
2014-06-24 14:56:27 +00:00
import "github.com/0xAX/go-alghoritms"
2014-06-21 16:59:23 +00:00
func main() {
2014-06-22 15:00:00 +00:00
arr := utils.RandArray(10)
fmt.Println("Initial array is:", arr)
fmt.Println("")
tmp := 0
for i := 0; i < len(arr); i++ {
for j := 0; j < len(arr) - 1; j++ {
if arr[j] > arr[j + 1] {
tmp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = tmp
}
}
}
fmt.Println("Sorted array is: ", arr)
2014-06-21 16:59:23 +00:00
}