Created
May 6, 2020 04:21
-
-
Save cedricconol/a28e1c036c6f040b9c5ac46810944124 to your computer and use it in GitHub Desktop.
optimized bubble sort in go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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