Skip to content

Commit 3438c48

Browse files
authored
Merge pull request #126 from qzqsmile/update_bubblesort_swap
update bubblesort swap
2 parents dd65dd3 + 13e206e commit 3438c48

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

sorts/bubble_sort.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@
22
package sorts
33

44
func bubbleSort(arrayzor []int) []int {
5-
6-
75
swapped := true
86
for swapped {
97
swapped = false
108
for i := 0; i < len(arrayzor)-1; i++ {
119
if arrayzor[i+1] < arrayzor[i] {
12-
swap(arrayzor, i, i+1)
10+
arrayzor[i+1], arrayzor[i] = arrayzor[i], arrayzor[i+1]
1311
swapped = true
1412
}
1513
}
1614
}
1715
return arrayzor
1816
}
19-
20-
func swap(arrayzor []int, i, j int) {
21-
tmp := arrayzor[j]
22-
arrayzor[j] = arrayzor[i]
23-
arrayzor[i] = tmp
24-
}

0 commit comments

Comments
 (0)