Skip to content

Instantly share code, notes, and snippets.

@rphuber
Created April 11, 2024 03:08
Show Gist options
  • Select an option

  • Save rphuber/f759707bbfd9787871f9645611651a3f to your computer and use it in GitHub Desktop.

Select an option

Save rphuber/f759707bbfd9787871f9645611651a3f to your computer and use it in GitHub Desktop.
func bubbleSort(slice []int) {
n := len(slice)
for {
swapped := false
for i := 1; i < n; i++ {
if slice[i-1] > slice[i] {
slice[i-1], slice[i] = slice[i], slice[i-1]
swapped = true
}
}
if !swapped {
break
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment