public class Main {
public static void main(String a[]){
int i;
int array[] = {7,1,5,4,13,11};
quick_srt(array,0,array.length-1);
System.out.print("nilai yang telah disusun");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+" ")
}
public static void quick_srt(int array[],int bag_kiri, int bag_kanan){
int i = bag_kiri;
int j = bag_kanan;
if (i >= j) {
return;
}
int pivot = array[(i + j) / 2];
while (i < j)
{
while (i<j && array[i] < pivot) {
i++;
}
while (i<j && array[j] > pivot) {
j--;
}
if (i < j) {
int T = array[i];
array[i] = array[j];
array[j] = T;
}
}
if (i < j) {
int T = j;
j = i;
i = T;
}
quick_srt(array, bag_kiri, i);
quick_srt(array, i == bag_kiri ? i+1 : i, bag_kanan);
}
}
No comments:
Post a Comment
fill it with what you want, but please not be anarky and vulgar....