Class QuickSort


  • public class QuickSort
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Comparator mComparator  
    • Constructor Summary

      Constructors 
      Constructor Description
      QuickSort​(java.util.Comparator comparator)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void qsort​(java.lang.Object[] a, int lo0, int hi0)
      This is a generic version of C.A.R Hoare's Quick Sort algorithm.
      void qsort​(java.lang.Object[] v, int left, int right, java.util.Comparator comp)  
      void sort​(java.lang.Object[] a)  
      void sort​(java.lang.Object[] a, int length)  
      private static void swap​(java.lang.Object[] a, int i, int j)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mComparator

        private java.util.Comparator mComparator
    • Constructor Detail

      • QuickSort

        public QuickSort​(java.util.Comparator comparator)
    • Method Detail

      • qsort

        public void qsort​(java.lang.Object[] v,
                          int left,
                          int right,
                          java.util.Comparator comp)
      • qsort

        private void qsort​(java.lang.Object[] a,
                           int lo0,
                           int hi0)
        This is a generic version of C.A.R Hoare's Quick Sort algorithm. This will handle arrays that are already sorted, and arrays with duplicate keys.
        If you think of a one dimensional array as going from the lowest index on the left to the highest index on the right then the parameters to this function are lowest index or left and highest index or right. The first time you call this function it will be with the parameters 0, a.length - 1.
        Parameters:
        a - an Object array
        lo0 - left boundary of array partition
        hi0 - right boundary of array partition
      • swap

        private static void swap​(java.lang.Object[] a,
                                 int i,
                                 int j)
      • sort

        public void sort​(java.lang.Object[] a)
      • sort

        public void sort​(java.lang.Object[] a,
                         int length)