Skip to content

Instantly share code, notes, and snippets.

@cedricconol
Created May 6, 2020 04:21
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 cedricconol/a28e1c036c6f040b9c5ac46810944124 to your computer and use it in GitHub Desktop.
Save cedricconol/a28e1c036c6f040b9c5ac46810944124 to your computer and use it in GitHub Desktop.
optimized bubble sort in go
func bubblesort(list []int, ascending bool) {
var N int = len(list)
var count int
for i := 1; i < N; i++ {
swapCount := pass(list, ascending)
count++
if swapCount == 1 {
break
}
}
fmt.Println("Number of iterations: ", count)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment