Package com.irurueta.sorting
Class SystemSorter<T>
java.lang.Object
com.irurueta.sorting.Sorter<T>
com.irurueta.sorting.QuicksortSorter<T>
com.irurueta.sorting.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.
Sorts instances of type T in provided arrays using Quicksort method.
-
Field Summary
Fields inherited from class com.irurueta.sorting.Sorter
DEFAULT_SORTING_METHOD
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns sorting method of this class.void
sort
(double[] array, int fromIndex, int toIndex) Sorts provided array in ascending order so thatarray[i - 1] < array[i]
for any valid i.void
sort
(float[] array, int fromIndex, int toIndex) Sorts provided array in ascending order so thatarray[i - 1] < array[i]
for any valid i.void
sort
(int[] array, int fromIndex, int toIndex) Sorts provided array in ascending order so thatarray[i - 1] < array[i]
for any valid i.void
sort
(long[] array, int fromIndex, int toIndex) Sorts provided array in ascending order so thatarray[i - 1] < array[i]
for any valid i.void
sort
(T[] array, int fromIndex, int toIndex, Comparator<T> comparator) Sorts provided array in ascending order so thatarray[i - 1] < array[i]
for any valid i.Methods inherited from class com.irurueta.sorting.QuicksortSorter
sortWithIndices, sortWithIndices, sortWithIndices, sortWithIndices, sortWithIndices
Methods inherited from class com.irurueta.sorting.Sorter
create, create, getInitialIndicesVector, median, median, median, median, median, median, median, median, median, median, median, median, select, select, select, select, select, select, select, select, select, select, select, select, sort, sort, sort, sort, sort, sort, sort, sortWithIndices, sortWithIndices, sortWithIndices, sortWithIndices, sortWithIndices, sortWithIndices, sortWithIndices, swap, swap, swap, swap, swap
-
Constructor Details
-
SystemSorter
public SystemSorter()
-
-
Method Details
-
sort
Sorts provided array in ascending order so thatarray[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 classQuicksortSorter<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
- IffromIndex > toIndex
.ArrayIndexOutOfBoundsException
- iffromIndex < 0
ortoIndex > array.length
.
-
sort
public void sort(double[] array, int fromIndex, int toIndex) Sorts provided array in ascending order so thatarray[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 classQuicksortSorter<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
- IffromIndex > toIndex
.ArrayIndexOutOfBoundsException
- iffromIndex < 0
ortoIndex > array.length
.
-
sort
public void sort(float[] array, int fromIndex, int toIndex) Sorts provided array in ascending order so thatarray[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 classQuicksortSorter<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
- IffromIndex > toIndex
.ArrayIndexOutOfBoundsException
- iffromIndex < 0
ortoIndex > array.length
.
-
sort
public void sort(int[] array, int fromIndex, int toIndex) Sorts provided array in ascending order so thatarray[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 classQuicksortSorter<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
- IffromIndex > toIndex
.ArrayIndexOutOfBoundsException
- iffromIndex < 0
ortoIndex > array.length
.
-
sort
public void sort(long[] array, int fromIndex, int toIndex) Sorts provided array in ascending order so thatarray[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 classQuicksortSorter<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
- IffromIndex > toIndex
.ArrayIndexOutOfBoundsException
- iffromIndex < 0
ortoIndex > array.length
.
-
getMethod
Returns sorting method of this class.- Overrides:
getMethod
in classQuicksortSorter<T>
- Returns:
- Sorting method.
-