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

26 lines
422 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 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] {
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
}