快速排序

2011-03-01  李卓华 

public class QuickSort{
public void quickSort(String[] strData, int left, int right){
String middle, temp;
int i, j;
i = left;
j = right;
middle = strData[(i+j)/2];
do{
while(strData[i].compareTo(middle) < 0 && i < right)
i++;
while(strData[j].compareTo(middle) > 0 && j > left)
j--;

if(i<=j){
temp = strData[i];
strData[i] = strData[j];
strData[j] = temp;
i++;
j--;
}
}while(i<=j);

if(i<right){
quickSort(strData, i, right);
}
if(j > left){
quickSort(strData, left, j);
}
}

public statck void main(String[] args){
QuickSort sort = new QuickSort();
sort.quickSort(strVoid, 0, strVoid.length - 1);
}
}
280°/2803 人阅读/0 条评论 发表评论

登录 后发表评论