We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 1ce1baa + a14abf1 commit 200793dCopy full SHA for 200793d
algorithm/sort/bubble_sort.md
@@ -80,11 +80,12 @@ import "fmt"
80
81
func BubbleSort(list []int) {
82
n := len(list)
83
- // 在一轮中有没有交换过
84
- didSwap := false
85
86
// 进行 N-1 轮迭代
87
for i := n - 1; i > 0; i-- {
+ // 在一轮中有没有交换过
+ didSwap := false
88
+
89
// 每次从第一位开始比较,比较到第 i 位就不比较了,因为前一轮该位已经有序了
90
for j := 0; j < i; j++ {
91
// 如果前面的数比后面的大,那么交换
code/sort/bubble.go
@@ -4,11 +4,12 @@ import "fmt"
4
5
6
7
8
9
10
11
12
13
14
15
0 commit comments