Skip to content

Instantly share code, notes, and snippets.

@etsangsplk
Forked from emre/bubbesort.go
Created March 29, 2019 23:21
Show Gist options
  • Save etsangsplk/bbab54e2b611c6d7a751285bd6bb2071 to your computer and use it in GitHub Desktop.
Save etsangsplk/bbab54e2b611c6d7a751285bd6bb2071 to your computer and use it in GitHub Desktop.
bubblesort in golang
package main
import "fmt"
func main() {
x := []int{
48, 96, 86, 68,
57, 82, 63, 70,
37, 34, 83, 27,
19, 97, 9, 17,
}
end := len(x) - 1
for {
if end == 0 {
break
}
for i := 0; i < len(x)-1; i++ {
if x[i] > x[i+1] {
x[i], x[i+1] = x[i+1], x[i]
}
}
end -= 1
}
fmt.Println(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment