Class SystemSorter<T>

Type Parameters:
T - Type of instances being sorted.

Where available, sort is based on Java SDK implementation, which also uses Quicksort, however Java SDK implementation does not offer the ability to retrieve indices when sorting

This class is based on algorithm found at Numerical Recipes. 3rd Edition. Cambridge Press. Chapter 8. p. 424 Sedgewick, R. 1978. "Implementing Quicksort Programs", Communications of the ACM, vol. 21, pp. 847-857.


public class SystemSorter<T> extends QuicksortSorter<T>
Sorts instances of type T in provided arrays using Quicksort method.
  • Constructor Details

    • SystemSorter

      public SystemSorter()
  • Method Details

    • sort

      public void sort(T[] array, int fromIndex, int toIndex, Comparator<T> comparator)
      Sorts provided array in ascending order so that array[i - 1] < array[i] for any valid i. This method modifies provided array so that after execution of this method array elements are ordered.
      Overrides:
      sort in class QuicksortSorter<T>
      Parameters:
      array - Array to be sorted. After execution of this method elements in array between fromIndex (inclusive) and toIndex (exclusive) are modified so that they are on ascending order.
      fromIndex - Index were sorting starts (inclusive).
      toIndex - Index were sorting stops (exclusive).
      comparator - Determines whether an element is greater or lower than another one.
      Throws:
      IllegalArgumentException - If fromIndex > toIndex.
      ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > array.length.
    • sort

      public void sort(double[] array, int fromIndex, int toIndex)
      Sorts provided array in ascending order so that array[i - 1] < array[i] for any valid i. This method modifies provided array so that after execution of this method array elements are ordered.
      Overrides:
      sort in class QuicksortSorter<T>
      Parameters:
      array - Array to be sorted. After execution of this method elements in array between fromIndex (inclusive) and toIndex (exclusive) are modified so that they are on ascending order.
      fromIndex - Index were sorting starts (inclusive).
      toIndex - Index were sorting stops (exclusive).
      Throws:
      IllegalArgumentException - If fromIndex > toIndex.
      ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > array.length.
    • sort

      public void sort(float[] array, int fromIndex, int toIndex)
      Sorts provided array in ascending order so that array[i - 1] < array[i] for any valid i. This method modifies provided array so that after execution of this method array elements are ordered.
      Overrides:
      sort in class QuicksortSorter<T>
      Parameters:
      array - Array to be sorted. After execution of this method elements in array between fromIndex (inclusive) and toIndex (exclusive) are modified so that they are on ascending order.
      fromIndex - Index were sorting starts (inclusive).
      toIndex - Index were sorting stops (exclusive).
      Throws:
      IllegalArgumentException - If fromIndex > toIndex.
      ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > array.length.
    • sort

      public void sort(int[] array, int fromIndex, int toIndex)
      Sorts provided array in ascending order so that array[i - 1] < array[i] for any valid i. This method modifies provided array so that after execution of this method array elements are ordered.
      Overrides:
      sort in class QuicksortSorter<T>
      Parameters:
      array - Array to be sorted. After execution of this method elements in array between fromIndex (inclusive) and toIndex (exclusive) are modified so that they are on ascending order.
      fromIndex - Index were sorting starts (inclusive).
      toIndex - Index were sorting stops (exclusive).
      Throws:
      IllegalArgumentException - If fromIndex > toIndex.
      ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > array.length.
    • sort

      public void sort(long[] array, int fromIndex, int toIndex)
      Sorts provided array in ascending order so that array[i - 1] < array[i] for any valid i. This method modifies provided array so that after execution of this method array elements are ordered.
      Overrides:
      sort in class QuicksortSorter<T>
      Parameters:
      array - Array to be sorted. After execution of this method elements in array between fromIndex (inclusive) and toIndex (exclusive) are modified so that they are on ascending order.
      fromIndex - Index were sorting starts (inclusive).
      toIndex - Index were sorting stops (exclusive).
      Throws:
      IllegalArgumentException - If fromIndex > toIndex.
      ArrayIndexOutOfBoundsException - if fromIndex < 0 or toIndex > array.length.
    • getMethod

      public SortingMethod getMethod()
      Returns sorting method of this class.
      Overrides:
      getMethod in class QuicksortSorter<T>
      Returns:
      Sorting method.