The detail contents of how to code and how it works just lie in the book written by Simon Harris and James Ross, want to know more? so check it out.
A general implementation of mergesort is, when there is more than one item in the list to be sorted, split the list in half, sort the halves, and then merge them together.
Shellsort breaks a large list of items into many smaller sublists, which are sorted independently using an insertion sort. While this sounds simple, the trick lies in repeating this process several times with careful creation of larger and larger sublists, until the whole list is sorted using an insertion sort on the final pass. The shellsort code works by successively sorting sublists of items that are evenly spaced inside the larger list of items. These lists start out with few items in them, with large gaps between the items. The sublists become progressively larger in size but fewer in number as the items are more closely spaced. The outermost loop in the main sort() method is concerned with H-sorting the sublists at progressively smaller increments, eventually H-sorting with H set to a value of 1, which means the list is completely sorted.
The first step in quicksort is to choose the partitioning item. This is the item that ends up in its final sorted position after this pass, and partitions the list into sections, with smaller items to the left and larger items to its right. You also initialize two indexes at the leftmost and rightmost of the remaining items. The algorithm proceeds by advancing the left and right indexes towards each other until they meet. As the left index proceeds, it stops when it finds an item that is larger than the partitioning item. As the right index proceeds, it stops when it encounters an item that is smaller than the partitioning item. The items are then swapped so that they are each in the appropriate part of the list. Remember that the idea is to have smaller items to the left and larger items to the right, althought not necessarily in sorted order.
本文详细介绍了排序算法中的梅尔排序与希尔排序的基本原理、实现方式及工作流程。梅尔排序通过将列表分为两半并递归排序来实现高效排序;而希尔排序则通过创建多个子列表并使用插入排序进行初步排序,最终通过逐步减小子列表间隔完成整个列表的排序。
2081

被折叠的 条评论
为什么被折叠?



