Here you can find the source of quickSort(String a[], int lo0, int hi0)
Parameter | Description |
---|---|
a | an array of <code>String</code>. |
lo0 | the low index to sort. |
hi0 | the high index to sort. |
static private void quickSort(String a[], int lo0, int hi0)
//package com.java2s; public class Main { /**/*from w w w .j a v a 2 s .c o m*/ * Internal recursive method to perform Quick Sort on name array. * * @param a an array of <code>String</code>. * @param lo0 the low index to sort. * @param hi0 the high index to sort. */ static private void quickSort(String a[], int lo0, int hi0) { int lo = lo0; int hi = hi0; String mid; if (hi0 > lo0) { // Arbitrarily establishing partition element as the array midpoint */ mid = a[(lo0 + hi0) / 2]; // loop through the array until indices cross while (lo <= hi) { // find the first element that is >= the partition element // starting from the left index. while ((lo < hi0) && (a[lo].compareTo(mid) < 0)) ++lo; // find an element that is <= the partition element // starting from the right index. while ((hi > lo0) && (a[hi].compareTo(mid) > 0)) --hi; // if the indexes have not crossed, swap if (lo <= hi) { swap(a, lo, hi); ++lo; --hi; } } // If the right index has not reached the left side of array, // sort the left partition. if (lo0 < hi) quickSort(a, lo0, hi); // If the left index has not reached the right side of array, // sort the right partition. if (lo < hi0) quickSort(a, lo, hi0); } } /** * Private method to swap two elements in the array * @param a an array of <code>String</code>. * @param i the index of the first element. * @param j the index of the second element. */ static private void swap(String a[], int i, int j) { String T; T = a[i]; a[i] = a[j]; a[j] = T; } }