Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Quick Sort in Java

Go down

Quick Sort in Java Empty Quick Sort in Java

Post  skyboard 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

Back to top Go down

Back to top

- Similar topics

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