Classification:
1) Insert sort (direct insert sort, hill Sort)
2) Swap sort (bubble sort, quick sort)
3) Select sort (Direct select sort, heap sort)
4) Merge sort
5) Allocation sort (cardinal sort)
Maximum required auxiliary space: merge sort
Minimum required secondary space: heap Ordering
Fastest Speed: Fast sorting
Unstable: Quick sort, hill sort, heap sort.
Let's take a look at the relationship between the 8 sorts:
1. Direct Insert Sort
(1) Basic idea: In the set of numbers to be sorted, assume that the number of front (n-1) [n>=2] is already a row
In a good order, now you want to insert the nth number into the ordinal number in front, so that the n number
It's also in the right order. This cycle is repeated until all the rows are in order.
(2) Example
(3) Implementation in Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Package Com.njue; Publicclass insertsort {public insertsort () {inta[]={49, 38, 65 |