You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-algorithms/sorting/gnome_sort.go

23 lines
290 B
Go

package main
/*
* Gnome sort - https://en.wikipedia.org/wiki/Gnome_sort
*/
func GnomeSort(arr []int) {
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--
}
}
}
}