The code is as follows:
Public classQuickSort {//exchanging elements at index I and J two in the data array Private Static voidSwap (datawrap[] data,intIintj) {Datawrap tmp=Data[i]; Data[i]=Data[j]; DATA[J]=tmp; } //the subsequence of the Start-end index range in the data array is processed so that all the less than the demarcation is worth on the left//all greater than the demarcation is worth putting on the right Private Static voidSubsort (Datawrap [] data,intStartintend) { //need to sort if(Start <end) { //take the first element as a cutoff valueDatawrap base =Data[start]; //I search from the left, searching for an index of an element greater than the cutoff value inti =start; //I search from the left, searching for the index of the element that is less than the cutoff value intj = End +1; while(true) { //find the index of an element greater than the cutoff value, or I have found end while(I < end && Data[++i].compareto (base) <=0); //Find the index of the element that is less than the cutoff value, or J has found the start place while(J > Start && data[--j].compareto (base) >=0); if(I <j) {Swap (data, I, j); } Else { Break; }} swap (data, start, j); //recursive left dial hand sequenceSubsort (data, start, j-1); //recursive right sub-sequenceSubsort (data, j+1, end); } } Public Static voidQuickSort (Datawrap [] data) {subsort (data,0, Data.length-1); } Public Static voidMain (string[] args) {datawrap[] data= { NewDatawrap (21, ""), NewDatawrap (30, ""), NewDatawrap (49, ""), NewDatawrap (30, ""), NewDatawrap (16, ""), NewDatawrap (9, "") }; System.out.println ("Before sorting: \ n" +java.util.Arrays.toString (data)); QuickSort (data); System.out.println ("After sorting: \ n" +java.util.Arrays.toString (data)); }}
Java Quick Sort