Quick Sort in Java Jeliot

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; 
    } 


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s