Simple Sequencing Methods - bubbling, select, insert, bucket sort

Bubble sort:
the basic idea: Every compare two adjacent elements, if they put them in the wrong order switching over.
I.e., if the number n of sorting, will be n-1 times operations. And each trip must compare two adjacent numbers from the first start, repeat this step until the last not yet homing number, the number is already homing is no need to compare.
Code is as follows: Here Insert Picture Description
Selection Sort:
the basic idea: each select a minimum (or maximum) data elements from the data element to be sorted, in a starting position of the sequence, then the data element never select a sorted minimum ( or maximum) data elements at the end of an ordered sequence. Because in this new insert data element earlier, every once singled out than it is a small data element, this newly elected smallest element is inserted at the end of an ordered sequence longer constitute a new order sequence.
Code is as follows:
Here Insert Picture Description
insertion sort:
the basic idea: The basic idea is that insertion sort: n the number of elements to be seen as a sort sorted list and an unordered list, at the beginning of a sorted list contains only elements, unordered list with the n-1 elements, the sorting process takes out from the first element of the unordered list, the sort codes which are sequentially compared with the ordered list of sort key element, it is inserted into the sorted list place, making the new order table.
Code:
Here Insert Picture Description
bucket sort:
the basic idea: n + 1 where we need buckets, used to represent every number between 0 ~ n times appear, each bucket role here is used to mark the times of occurrence of each number and then direct each bucket has a few numbers, they output index (array index) several times bucket on it.
Here Insert Picture Description

Released six original articles · won praise 0 · Views 71

Guess you like

Origin blog.csdn.net/qq_45949060/article/details/104088313