Sorting algorithms/Bubble sort: Difference between revisions

Go solution
m (→‎Icon and Unicon: header simplification)
(Go solution)
Line 842:
END DO
END SUBROUTINE Bubble_Sort</lang>
=={{header|Fortran}}==
Per task pseudocode:
<lang go>package main
 
import "fmt"
 
func main() {
list := []int{31, 41, 59, 26, 53, 58, 97, 93, 23, 84}
fmt.Println("unsorted:", list)
 
bubblesort(list)
fmt.Println("sorted! ", list)
}
 
func bubblesort(a []int) {
for itemCount := len(a) - 1; ; itemCount-- {
hasChanged := false
for index := 0; index < itemCount; index++ {
if a[index] > a[index+1] {
a[index], a[index+1] = a[index+1], a[index]
hasChanged = true
}
}
if hasChanged == false {
break
}
}
}</lang>
 
=={{header|Groovy}}==
1,707

edits