Public Static voidQuickSort (int[] A,intLowintHigh ) { if(Low <High ) { intPivotpos = Partition2 (A, Low, high);//completion of pivot positioningQuickSort (A, Low, pivotpos-1); QuickSort (A, Pivotpos+ 1, high); } } Public Static intPartition1 (int[] A,intLowintHigh ) { //two subscript indexes scan from end to end, cut a benchmark radish pivot, leave a pit, back and forth still radish, whether to throw: Compare with pivot value size relationship//Two little man low and high at both ends//There is a pit in the low, then high from him to find radish throw, find than pivot small throw over//The high Place has the pit, from the low place to find the radish to throw, found is bigger than pivot to throw over//after throwing the difference between the end of the 1 pits, then the original dug up the benchmark radish pivot seat, positioning! intPivot = A[low];//takes the first element of the current table as the pivot value, leaving a pit at the low while(Low < High) {//loop out of condition, low and high keep approaching until (low = high) while(Low < High && A[high] >=pivot) { //If the high radish is larger than the benchmark Radish pivot, do not deal with, higher, go, narrow the rangehigh--; } A[low]= A[high];//High in the radish than the benchmark radish pivot small, throw to the low place of the pit, leaving himself a pit, located high while(Low < High && A[low] <=pivot) { //If the low radish is smaller than the benchmark Radish pivot, do not handle it, lower the range .low++; } A[high]= A[low];//Low radish than benchmark radish pivot big, throw to high place pit, oneself left a pit, located at Low} A[low]= pivot;//Put pivot on the last pit, no pits. returnLow//The loop jumps out, low = high = pivot should be in the pit}
Quick Sort algorithm--two little guys throwing carrots