Skip to content

Commit fff39ff

Browse files
committed
bubble sort
1 parent 9c5f477 commit fff39ff

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

1_bubble_sort.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ package algorithm
22

33
// BubbleSort ..
44
// No.1
5-
// 冒泡排序 (稳定)
5+
// 冒泡排序 (稳定)算法步骤:
6+
// 1. 比较相邻的元素。如果第一个比第二个大,就交换他们两个。
7+
// 2. 对每一对相邻元素做同样的工作,从开始第一对到结尾的最后一对。这步做完后,最后的元素会是最大的数。
8+
// 3. 针对所有的元素重复以上的步骤,除了最后一个。
9+
// 4. 持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需求比较。
610
func BubbleSort(arr []int) []int {
711
len := len(arr)
812
for i := 0; i < len-1; i++ {

0 commit comments

Comments
 (0)