I'm just starting in Go.
Please review the below code, and let me know what I can improve in this code.
//BubbleSort takes an []int {7,5,6,9,8} and returns {5,6,7,8,9}
func BubbleSort(arr []int) []int {
keepRunning := true
for keepRunning {
keepRunning = false
for i := 0; i < len(arr)-1; i++ {
a := arr[i]
b := arr[i+1]
if a > b {
arr[i], arr[i+1] = b, a
keepRunning = true
}
}
}
return arr
}
//edit In this case, I'm doing return simply cause I want to return a new copy, and not modify the original.
But I recently as well learned about GO's GC tricolor pattern. Which will discard the variable until there are no connections left.
So I guess I will need to use the original variable and pass it around and let the code modify the original Slice itself.