PackageCom.swift;Importjava.util.ArrayList;Importjava.util.Collections;ImportJava.util.Comparator;Importjava.util.List; Public classQuickSort {/** Quick Sort*/ Public Static voidMain (string[] args) {int[] strvoid =New int[] {11, 66, 22, 0, 55, 2, 0, 11 }; QuickSort Sort=NewQuickSort (); Sort.quicksort (Strvoid,0, Strvoid.length-1); for(inti = 0; i < strvoid.length; i++) {System.out.println (Strvoid[i]+ " "); } //Sort by Comparatorlist<integer> list =NewArraylist<integer>(); for(Integer i:strvoid) {list.add (i); } collections.sort (List,NewComparator<integer>() {@Override Public intCompare (integer arg0, integer arg1) {intnum = arg1-arg0; returnnum; } }); for(Integer i:list) {System.out.print (i+ " | "); } } voidQuickSort (int[] strdate,intLeftintRight ) { intI, J, T, Key; if(Left >Right )return; Key= Strdate[left];//the base number is stored in temp.i =Left ; J=Right ; while(I! =j) {//from the back of the key to find the smaller or wait for the key to the left while(Strdate[j] > key && i <j) J--; //I used to find bigger than key on the right side of key while(Strdate[i] <= key && i <j) I++; //less than the swap position, equal to stop if(I <j) {T=Strdate[i]; Strdate[i]=Strdate[j]; STRDATE[J]=BT; } } //Two when the pointer is equal, the value of the first position is swapped with the value at the same position, completing the first round of sortingStrdate[left] =Strdate[i]; Strdate[i]=key; QuickSort (Strdate, left, I-1);//proceed to the left, here is a recursive processQuickSort (strdate, i + 1, right);//proceed to the right, here is a recursive process }}
This is my train of thought, should belong to a two-way fast sort, a quick sort of solution too many ideas, there is a single road, two, three road, each kind of writing also has different, everyone's ideas are strange.
Java algorithm interview question: Design a quick sort. Two-way fast sequencing, simple and easy to understand.