Skip to content

Instantly share code, notes, and snippets.

@cipepser
Created January 9, 2017 06:31
Show Gist options
  • Save cipepser/95666e2ef1f45fece4b45fbafdff0f27 to your computer and use it in GitHub Desktop.
Save cipepser/95666e2ef1f45fece4b45fbafdff0f27 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func BubbleSort(a []int) []int {
for i := 0; i < len(a) - 1; i++ {
for j := 0; j < len(a) - i - 1; j++ {
if a[j] > a[j + 1] {
a[j], a[j + 1] = a[j + 1], a[j]
}
}
}
return a
}
func main() {
a := []int{2, 4, 5, 1, 3}
fmt.Println(BubbleSort(a))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment