go-dsa
go-dsa copied to clipboard
Comparison issue
https://github.com/spring1843/go-dsa/blame/adc15f7574794bfed14bc10c1689415323fa619c/array/bubble_sort.go#L7
the implementation is comparing the elements in a inefficient way
please see the comparison bellow
func bubbleSort(input []int) []int {
swapped := true
for swapped {
swapped = false
for i := 1; i < len(input); i++ {
if input[i-1] > input[i] {
input[i], input[i-1] = input[i-1], input[i]
swapped = true
}
}
}
return input
}
@gledsoul thank you for finding this enhancement. Looks like a good change, would you like to open a PR to suggest this improvement?