package javaapplication1;
/**
*
* @author agung
*/
public class search {
public void quick(String a[], int lo0, int hi0){
int lo = lo0;
int hi = hi0;
String mid;
if (hi0 > lo0) {
mid = a[(lo0 + hi0) / 2];
while (lo <= hi) { while ((lo < hi0) && (a[lo].compareTo(mid) > 0))
++lo;
while ((hi > lo0) && (a[hi].compareTo(mid) < 0))
--hi;
if (lo <= hi) {
String t = a[hi];
a[hi] = a[lo];
a[lo] = t;
++lo;
--hi;
}
}
/*
* If the right index has not reached the left side of array must now sort the left partition.
*/
if (lo0 < hi)
quick(a, lo0, hi);
/*
* If the left index has not reached the right side of array must now sort the right partition.
*/
if (lo < hi0)
quick(a, lo, hi0);
}
}
public void test() {
String[] srcArray = new String[] {"com","abc","name","example","java"};
quick(srcArray, 0, srcArray.length-1);
printArray(srcArray);
}
private void printArray(String[] array) {
for(int i=0; i
System.out.print(array[i]+"\t");
// jTextArea1.append(array[i]+"\n");
}
System.out.println("\n");
} public static void main(String[] args) {
new search().test();
}}
System.out.print(array[i]+"\t");
// jTextArea1.append(array[i]+"\n");
}
System.out.println("\n");
} public static void main(String[] args) {
new search().test();
}}
Kode Iklan anda yang ingin ada di sebelah kiri disini
Kode Iklan anda yang ingin ada di sebelah kanan disini
0 komentar:
Posting Komentar