-
Notifications
You must be signed in to change notification settings - Fork 194
希尔排序 #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
作者你好,在step内部使用的好像不是插入排序,更像是冒泡排序,代码对比如下,请指教:
|
确实,里面是通过交换,而不是挪位来插入的,如果你看过插入排序那一章的逻辑,是元素向右挪位,然后找到位置插进去,其实我们也可以改成那样。 |
多次分组进行插入排序,使得最后对整个列表排序时,列表已经是大致有序的,那么最后一次插入排序就会时间复杂度就趋向线性的。
|
越有序的数列,直接插入排序的效率越高,希尔排序通过分组使用直接插入排序,因为步长比 1 大,在一开始可以很快将无序的数列变得不那么无序,比较和交换的次数也减少,直到最后使用步长为 1 的直接插入排序,数列已经是相对有序了,所以时间复杂度会稍好一点。 |
感觉这个分组排序的想法和快速排序好像呀? |
九九归一。 |
这代码是不是有点问题 ? 而你提供的代码运行结果是这样的: 第一次:[2 3 5 9 7 0 8 6] 所以我修改了下代码:
|
该节有纰漏,已修改了若干次,可以重新阅读。 |
https://hunterhug.github.io/goa.c/#/algorithm/sort/shell_sort
Description
The text was updated successfully, but these errors were encountered: