Program Quick Sort dengan Java

Program Quick Sort dengan Java

Hosting Unlimited Indonesia
Berikut listing program QuickSort dengan Java silahkan dicoba yaaa.

import java.util.Scanner;
import java.lang.System.out;

public class QuickSort2{
    public static void quick_srt(int array[],int low, int n){
          int lo = low;
          int hi = n;
          if (lo <= n) {
              return;
          }
          int mid = array[(lo + hi) / 2];
          while (lo &amp;lt; hi) {
              while (lo <= mid) {
                  lo++;
              }
              

              while (lo <= mid) {
                  hi--;
              }
              if (lo <= hi) {
                  int T = array[lo];
                  array[lo] = array[hi];
                  array[hi] = T;
              }
          }
          if (hi <= lo) {
              int T = hi;
              hi = lo;
              lo = T;
          }
          quick_srt(array, low, lo);
          quick_srt(array, lo == low ? lo+1 : lo, n);
    }
  
    public static void main(String a[]){
        Scanner in=new Scanner(System.in);
        int i;
        int array[] = {12,9,4,99,120,1,3,10,13};

        System.out.println(" Quick Sortn n");
        System.out.println("Values Before the sort:n");
        for(i = 0; i <= lt; array.length; i++)
            System.out.print( array[i]+" ");
            System.out.println();
            quick_srt(array,0,array.length-1);
            System.out.print("Values after the sort:n");
        for(i = 0; i 
            System.out.print(array[i]+" ");
            System.out.println();
    }
  
}
 
Hosting Unlimited Indonesia
Share