1.3 冒泡排序 #30
Replies: 9 comments 3 replies
-
python中交换两个两个数可以不使用temp暂存 |
Beta Was this translation helpful? Give feedback.
-
然后将第 2 个元素与第 3 个元素比较,也就是将 2 和 3 进行比较。因为 2 < 3,所以不用交换; 这句话有笔误吧? 此时第二个元素是6 而不是2 |
Beta Was this translation helpful? Give feedback.
-
for i in range(len(arr)): 这里需要-1吧 |
Beta Was this translation helpful? Give feedback.
-
是的,需要减 1。已更正,感谢指正。 |
Beta Was this translation helpful? Give feedback.
-
代码实现没有最佳时间复杂度O(n)的优化,需要在第二个循环判断是否进行了位置交换 |
Beta Was this translation helpful? Give feedback.
-
打卡 |
Beta Was this translation helpful? Give feedback.
-
def bubble_sort(arr): |
Beta Was this translation helpful? Give feedback.
-
你好,2.冒泡排序算法步骤中,第二趟冒泡中的第4点有个是“经过第 2 趟排序,使得数组中第 2 个值最大元素被安置在第 n-1 个位置上。“,原文中笔误写成第n个位置了。 |
Beta Was this translation helpful? Give feedback.
-
hello |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
1.3 冒泡排序
1.3 冒泡排序 # 1. 冒泡排序算法思想 # 冒泡排序(Bubble Sort)基本思想:
第 i (i = 1,2,… ) 趟排序时从序列中前 n - i + 1 个元素的第 1 个元素开始,相邻两个元素进行比较,若前者大于后者,两者交换位置,否则不交换。
冒泡排序
https://algo.itcharge.cn/01_array/01_03_array_bubble_sort/
Beta Was this translation helpful? Give feedback.
All reactions