1.5 插入排序 #63
Replies: 11 comments 5 replies
-
|
简单来说,「选择排序算法」是在每一趟排序中,将无序序列的第 1 个元素,插入到有序序列的适当位置上。 |
Beta Was this translation helpful? Give feedback.
-
已修正,感谢指正~~ |
Beta Was this translation helpful? Give feedback.
-
|
打卡 |
Beta Was this translation helpful? Give feedback.
-
|
for i in range(1, len(nums)): |
Beta Was this translation helpful? Give feedback.
-
|
2.2步应该是比num[1]大的元素向后移动一位吧 |
Beta Was this translation helpful? Give feedback.
-
|
文字描述部分是否写反了?“从右到左遍历有序区间中的元素,将比 𝑛𝑢𝑚𝑠[1]小的元素向后移动 1 位。”,是否应该是将比num[1]大的元素往后移动一位?按照原文的说法输出就会是从大到小而不是从小到大。 |
Beta Was this translation helpful? Give feedback.
-
|
自己改下缩进 lst = [5,2,3,6,1,4] |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
自己写了一个简单的 |
Beta Was this translation helpful? Give feedback.
-
这样子写应该不算是插入排序吧 |
Beta Was this translation helpful? Give feedback.
-
|
个人感觉有序区间内的比较和插入其实就是冒泡算法,不过改成了从右向左,遇到大于temp的值就交换位置,知道遇到比temp小的,此时temp已经被连续交换送到了恰当的位置。 |
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.5 插入排序
插入排序 # 1. 插入排序算法思想 # 插入排序(Insertion Sort)基本思想: 将整个序列分为两部分:前面 i 个元素为有序序列,后面 n - i 个元素
https://algo.itcharge.cn/01_array/01_05_array_insertion_sort/
Beta Was this translation helpful? Give feedback.
All reactions