go-dsa icon indicating copy to clipboard operation
go-dsa copied to clipboard

Comparison issue

Open gledsoul opened this issue 1 year ago • 1 comments

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 avatar Jun 13 '24 17:06 gledsoul

@gledsoul thank you for finding this enhancement. Looks like a good change, would you like to open a PR to suggest this improvement?

spring1843 avatar Jun 26 '24 19:06 spring1843