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