Yesterday I looked at the quick sorting, "algorithm" this book gives the realization of the sense of understanding is not very intuitive, so I combined with other books to write a fast algorithm. But there is no way to run the results, it seems that eclipse has been running, must kill the process to be able. I just learned is not very understanding, first put out the code, I hope someone can give advice.
1 PackageJava;2 3 Public classquicksort1{4 5 Public Static voidQuickSort (int[] a) {6QuickSort (A, 0, a.length-1);7 }8 Private Static voidQuickSort (int[] A,intFirstintLast ) {9 if(First <Last ) { Ten intPivotindex =partition (A, first, last); OneQuickSort (A, first, pivotIndex-1); AQuickSort (A, Pivotindex + 1, last); - } - } the - Private Static intPartitionint[] A,intFirstintLast ) { - - intLow = first + 1; + intHigh =Last ; - intPivot =A[first]; + A while(true){ at while(A[low] <= pivot && Low <Last ); -low++; - while(A[high] >= pivot && High >First ); -high--; - if(Low >=High ) - Break; in inttemp =A[low]; -A[low] =A[high]; toA[high] =temp; + } -A[first] =A[high]; theA[high] =pivot; * returnHigh ; $ }Panax Notoginseng - Private Static voidShowint[] a) { the for(inti = 0; i < a.length; i++) +System.out.print (A[i] + ""); A System.out.println (); the } + - Public Static voidMain (string[] args) { $ int[] A ={30, 1, 23, 232, 7, 10, 90, 17, 8}; $ QuickSort (a); - Show (a); - } the}
Problems with quick sorting