1 Packagelog;2 3 Public classTest4 {4 5 /**6 * Java algorithm---fast sorting7 * 8 * @paramargs9 */Ten Public Static voidMain (string[] args) { One //arrays that need to be sorted A intArr[] = {49, 20, 36, 51, 18, 94, 61, 31, 50 }; - //loop out the contents of the array -System.out.println ("Before sorting:"); the for(intA:arr) { -System.out.print (A + "\ T")); - } - System.out.println (); + - if(Arr.length > 0) { +Sort (arr, 0, Arr.length-1); A } at //loop out the contents of the array -System.out.println ("After sorting:"); - for(intA:arr) { -System.out.print (A + "\ T")); - } - System.out.println (); in - } to + Public Static intGetmiddle (int[] list,intLowintHigh ) { - inttemp =List[low]; the while(Low <High ) { * while(Low < High && List[high] >=temp) { $high--;Panax Notoginseng } -List[low] =List[high]; the while(Low < High && List[low] <=temp) { +low++; A } theList[high] =List[low]; + } -List[low] =temp; $ returnLow ; $ } - - Public Static voidSortint[] list,intLowintHigh ) { the if(Low <High ) { - intMiddle =Getmiddle (list, low, high);WuyiSort (list, low, middle-1); theSort (list, middle + 1, high); - } Wu } - About}
Here's the thing. Console output
Sort the Java algorithm--------(4) Quick sort