Skip to content

Commit

Permalink
bubblesort ignore last index
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangbits committed May 31, 2020
1 parent 027af77 commit 6487796
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion c2-m1/bubbleSort.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Swap(pos *int, nextPos *int) {
// BubbleSort implements sorting algorithm over a slice of
// integer
func BubbleSort(sli []int) []int {
for i := range sli {
for i := range sli[:len(sli)-1] {
for j := range sli[:len(sli)-1-i] {
if sli[j] > sli[j+1] {
Swap(&sli[j], &sli[j+1])
Expand Down

0 comments on commit 6487796

Please sign in to comment.