Skip to content

Instantly share code, notes, and snippets.

@stojg
Last active October 12, 2015 01:37
Show Gist options
  • Save stojg/3951272 to your computer and use it in GitHub Desktop.
Save stojg/3951272 to your computer and use it in GitHub Desktop.
go implementation of bubble sort
package main
import "fmt"
func main() {
list := []int{1, 8, 10, 23, 3, -1, 2, 2, 6, 3, 4}
fmt.Println(list)
bubbleSort(list)
fmt.Println(list)
}
// My first bubble sort
// list is passed as reference
func bubbleSort(list []int) {
for i := 0; i < len(list)-1; i++ {
for j := i + 1; j < len(list); j++ {
if list[j] < list[i] {
list[i], list[j] = list[j], list[i]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment