/** ********************* * Quick sort recursively. * * @param paraStart The start index. * @param paraEnd The end index. ********************* */ publicvoidquickSortRecursive(int paraStart, int paraEnd) { // Nothing to sort. if (paraStart >= paraEnd) { return; } // Of if
// Find the position for the pivot. // At the same time move smaller elements to the left and bigger one to the // right. while (true) { while ((data[tempLeft].key < tempPivot) && (tempLeft < tempRight)) { tempLeft++; } // Of while
while ((data[tempRight].key >= tempPivot) && (tempLeft < tempRight)) { tempRight--; } // Of while
if (tempLeft < tempRight) { // Swap. System.out.println("Swapping " + tempLeft + " and " + tempRight); tempNodeForSwap = data[tempLeft]; data[tempLeft] = data[tempRight]; data[tempRight] = tempNodeForSwap; } else { break; } // Of if } // Of while
// Swap if (data[tempLeft].key > tempPivot) { tempNodeForSwap = data[paraEnd]; data[paraEnd] = data[tempLeft]; data[tempLeft] = tempNodeForSwap; } else { tempLeft++; } // Of if