public class QuickSort{
void QuickSort(String[] pData, int left, int right) {
int i, j;
String middle, strTemp;
i = left;
j = right;
middle = pData[(left + right) / 2];
do {
while ((pData[i].compareTo(middle) < 0) && (i < right)){
i++;
}
while ((pData[j].compareTo(middle) > 0) && (j > left)){
j--;
}
if (i <= j) {
strTemp = pData[i];
pData[i] = pData[j];
pData[j] = strTemp;
i++;
j--;
}
} while (i <= j);// 如果两边扫描的下标交错,就停止(完成一次)
if (left < j)
QuickSort(pData, left, j);
if (right > i)
QuickSort(pData, i, right);
}
/**
* @param args
*/
public static void main(String[] args) {
String[] StrinArr={"ab","ef","cd","gh","ij"};
QuickSort a =new QuickSort();
a.QuickSort(StrinArr, 0, StrinArr.length-1);
for(int i=0;i System.out.println(StrinArr[i]);
}
}
}
阅读(969) | 评论(1) | 转发(0) |