Quick Sort in Java Jeliot

Posted by Didi Setyapramana On 8:34 AM 0 komentar

import jeliot.io.*;

public class QuickSort{
  public static void main(String a[]){
    int i;
    int array[] = {12,9,4,29,7,1,3,10};
    System.out.println("Values Before the sort:\n");
    //for(i = 0; i < array.length; i++)
      //System.out.print( array+"  ");
    System.out.println();
    quickSort(array,0,7);
    System.out.print("Values after the sort:\n");
    for(i = 0; i <array.length; i++)
      System.out.print(array+"  ");
    System.out.println();
    System.out.println("PAUSE");
  }

 public static int partition(int arr[], int left, int right) { 
      int i = left, j = right; 
      int tmp; 
      int pivot = arr[(left + right) / 2]; 

      while (i <= j) { 
            while (arr < pivot) 
                  i++; 
            while (arr[j] > pivot) 
                  j--; 
            if (i <= j) { 
                  tmp = arr; 
                  arr = arr[j]; 
                  arr[j] = tmp; 
                  i++; 
                  j--; 
            } 
      }; 
      return i; 
    } 

Categories:

0 Response for the "Quick Sort in Java Jeliot"

Post a Comment