2
0
mirror of https://github.com/0xAX/go-algorithms synced 2024-11-13 13:10:30 +00:00
go-algorithms/sorting/gnome_sort.go
2014-06-24 21:10:25 +06:00

35 lines
464 B
Go

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