Skip to content

Instantly share code, notes, and snippets.

@Bablzz
Last active October 13, 2020 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bablzz/088ee22185f46f5eb1454edbaa31ba0e to your computer and use it in GitHub Desktop.
Save Bablzz/088ee22185f46f5eb1454edbaa31ba0e to your computer and use it in GitHub Desktop.
Bubble sort
package main
// worst n^2
// best n
import (
"fmt"
)
func main() {
arr := []int{2,5,4,-8,9,1}
for i, _:= range arr {
for j := 0; j < len(arr); j++ {
if arr[i] < arr[j] {
swap := arr[i]
arr[i] = arr[j]
arr[j] = swap
}
}
}
fmt.Println(arr)
}
// => [-8 1 2 4 5 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment