Quick Sort in Java

View previous topic View next topic Go down

Quick Sort in Java

Post  skyboard on Wed Sep 21, 2011 10:33 pm

public class QuickSort{
private int[] numbers;
private int number;

public void sort(int[] values){
if(values==null||values.length==0)
return;
this.numbers=values;
number=values.length;
quicksort(0,number-1);
}

private void quicksort(int low, int high){
int i=low; int j=high;
int pivot=numbers[low+(low+high)/2];
while(i<=j){
while(numbers[i]<pivot){
i++;
}
while(numbers[j]>pivot)
j--;
if(i<=j){
exchange(i,j);
i++;j--;
}

}
if(low<i)
quicksort(low,j);
if(i<high)
quicksort(i,high);
}
}

skyboard

Posts : 31
Join date : 2011-09-03

View user profile

Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum