Brief description
Previous data structure and algorithm courses to learn the algorithm are almost forgotten, so still want to tidy up the knowledge point review, good memory than bad pen.
I'll start with one. Introduce these algorithms and implementations, and then summarize them at a later time. First, start with the quick sort.
The algorithm idea is simple to describe:
A quick sort is an essential improvement to the bubbling sort. Its basic idea is that the length of the sequencing sequence can be drastically reduced after a scan. In a bubbling sort, a scan can only ensure that the number of maximum values is moved to the correct position, while the length of the sequence to be sorted may be reduced by only 1. Quick sort by a scan, you can make sure that the number of the left is smaller and the number on the right is larger than it. It then uses the same method to manipulate the left and right sides of the number until there is only one element to the left of the datum point.
Fast sequencing is not stable. Optimal condition algorithm time complexity O (nlog2n), Worst O (n2)
Algorithm implementation
Public classsort{ Public Static voidMain (string[] args) {int[] arr = {4,3,6,1,5,2}; Kssort (arr,0,arr.length-1); System.out.println (arrays.tostring (arr)); } Private Static voidKssort (int[] A,intLowintHigh ) { if(low<High ) { intMID =Getmid (A,low,high); Kssort (A,low,mid-1); Kssort (A,mid+1, high); } } Private Static intGetmid (int[] A,intLowintHigh ) { intBase =A[low]; while(low!=High ) { while(lowbase) { High--; } swap (A,low,high); while(lowbase) { Low++; } swap (A,low,high); } returnA[low]; } Private Static voidSwapint[] A,intLowintHigh ) { inttemp =A[low]; A[low]=A[high]; A[high]=temp; } }
Okay, look at the results.
Sorting algorithm-(1) Quick sort