Sorting algorithms/Comb sort: Difference between revisions

Go solution
m (→‎Icon and Unicon: header simplification)
(Go solution)
Line 440:
end program Combsort_Demo</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)
combSort()
fmt.Println("after: ", a)
}
 
func combSort() {
if len(a) < 2 {
return
}
for gap := len(a); ; {
if gap > 1 {
gap = gap * 4 / 5
}
var swapped bool
for i := 0; ; {
if a[i] > a[i+gap] {
a[i], a[i+gap] = a[i+gap], a[i]
swapped = true
}
i++
if i+gap >= len(a) {
break
}
}
if gap == 1 && !swapped {
break
}
}
}</lang>
 
=={{header|Haskell}}==
1,707

edits