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 15:10:43 +00:00
|
|
|
import "github.com/0xAX/go-algorithms"
|
2014-06-21 16:59:23 +00:00
|
|
|
|
|
|
|
func main() {
|
2018-01-24 09:40:41 +00:00
|
|
|
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] {
|
2019-05-12 18:53:24 +00:00
|
|
|
arr[j],arr[j+1] = arr[j+1],arr[j]
|
2018-01-24 09:40:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Sorted array is: ", arr)
|
2014-06-21 16:59:23 +00:00
|
|
|
}
|