UNB/ CS/ David Bremner/ teaching/ old/ cs1083/ java/ QuickSort.java
public class QuickSort
{
    private static int partition(int[] a,int from,int to){
        int pivot = a[from];
        int i = from;
        for (int j=from+1; j<= to; j++)
            if(a[j] <= pivot ) {
                i++;
                int temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        a[from]=a[i];
        a[i]=pivot;
        return i;
    }
    //
    /**
       Sorts a range of an array, using the merge sort
       algorithm.
       @param a the array to sort
       @param from the first index of the range to sort
       @param to the last index of the range to sort
    */
    public static void quickSort(int[] a, int from,
                                 int to){

        if (from >= to) return;

        int mid=partition(a,from,to);

        quickSort(a, from, mid-1);
        quickSort(a, mid+1, to);

    }
   /**
      Sorts an array, using the merge sort algorithm.
      @param a the array to sort
   */
   public static void sort(int[] a)
   {  quickSort(a, 0, a.length - 1);
   }


    public static void main(String[] args){
        int [] data= ArrayUtil.randomIntArray(100,1000);

        ArrayUtil.print(data);

        sort(data);

        ArrayUtil.print(data);

    }

}
//