Sorting algorithms/Gnome sort: Difference between revisions
Go solution
(withdrawn for debugging) |
(Go solution) |
||
Line 500:
end program example</lang>
=={{header|Go}}==
<lang go>package main
import "fmt"
var a = []int{170, 45, 75, -90, -802, 24, 2, 66}
func main() {
fmt.Println("before:", a)
gnomeSort()
fmt.Println("after: ", a)
}
func gnomeSort() {
for i, j := 1, 2; i < len(a); {
if a[i-1] > a[i] {
a[i-1], a[i] = a[i], a[i-1]
i--
if i > 0 {
continue
}
}
i = j
j++
}
}</lang>
=={{header|Haskell}}==
|