Ring a Bell : Three Sort Algorithms

 

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.

你可能感兴趣的:(Algorithm,list,each,idea,merge,sorting)