public final class Sorting extends Object
Modifier and Type | Method and Description |
---|---|
static void |
mergeSort(byte[] array,
int start,
int end)
Perform a merge sort on a range of a byte array, using numerical order.
|
static void |
mergeSort(byte[] array,
int start,
int end,
ByteComparator comp)
Perform a merge sort on a range of a byte array using a specified ordering.
|
static void |
mergeSort(char[] array,
int start,
int end)
Perform a merge sort on a range of a char array, using numerical order.
|
static void |
mergeSort(char[] array,
int start,
int end,
CharComparator comp)
Perform a merge sort on a range of a char array using a specified ordering.
|
static void |
mergeSort(double[] array,
int start,
int end)
Perform a merge sort on a range of a double array using a Double.compare as an ordering.
|
static void |
mergeSort(double[] array,
int start,
int end,
DoubleComparator comp)
Perform a merge sort on a range of a double array using a specified ordering.
|
static void |
mergeSort(float[] array,
int start,
int end)
Perform a merge sort on a range of a float array using Float.compare for an ordering.
|
static void |
mergeSort(float[] array,
int start,
int end,
FloatComparator comp)
Perform a merge sort on a range of a float array using a specified ordering.
|
static void |
mergeSort(int[] array,
int start,
int end) |
static void |
mergeSort(int[] array,
int start,
int end,
IntComparator comp)
Perform a merge sort on a range of a int array using numerical order.
|
static void |
mergeSort(int fromIndex,
int toIndex,
IntComparator c,
Swapper swapper)
Sorts the specified range of elements according to the order induced by the specified comparator.
|
static void |
mergeSort(long[] array,
int start,
int end)
Perform a merge sort on a range of a long array using numerical order.
|
static void |
mergeSort(long[] array,
int start,
int end,
LongComparator comp)
Perform a merge sort on a range of a long array using a specified ordering.
|
static void |
mergeSort(short[] array,
int start,
int end)
Perform a merge sort on a range of a short array, using numerical order.
|
static void |
mergeSort(short[] array,
int start,
int end,
ShortComparator comp) |
static <T extends Comparable<? super T>> |
mergeSort(T[] array,
int start,
int end)
Perform a merge sort of the specific range of an array of objects that implement
Comparable.
|
static <T> void |
mergeSort(T[] array,
int start,
int end,
Comparator<T> comp)
Perform a merge sort on the specified range of an array.
|
static void |
quickSort(byte[] array,
int start,
int end,
ByteComparator comp)
Sorts the specified range in the array in a specified order.
|
static void |
quickSort(char[] array,
int start,
int end,
CharComparator comp)
Sorts the specified range in the array in a specified order.
|
static void |
quickSort(double[] array,
int start,
int end,
DoubleComparator comp)
Sorts the specified range in the array in a specified order.
|
static void |
quickSort(float[] array,
int start,
int end,
FloatComparator comp)
Sorts the specified range in the array in a specified order.
|
static void |
quickSort(int[] array,
int start,
int end,
IntComparator comp)
Sorts the specified range in the array in a specified order.
|
static void |
quickSort(int start,
int end,
IntComparator comp,
Swapper swap)
Sorts some external data with QuickSort.
|
static void |
quickSort(long[] array,
int start,
int end,
LongComparator comp)
Sorts the specified range in the array in a specified order.
|
static void |
quickSort(short[] array,
int start,
int end,
ShortComparator comp)
Sorts the specified range in the array in ascending numerical order.
|
static <T extends Comparable<? super T>> |
quickSort(T[] array,
int start,
int end)
Sort the specified range of an array of object that implement the Comparable
interface.
|
static <T> void |
quickSort(T[] array,
int start,
int end,
Comparator<T> comp)
Sorts the specified range in the array in a specified order.
|
public static void quickSort(byte[] array, int start, int end, ByteComparator comp)
array
- the byte
array to be sorted.start
- the start index to sort.end
- the last + 1 index to sort.comp
- the comparison that determines the sort.IllegalArgumentException
- if start > end
.ArrayIndexOutOfBoundsException
- if start < 0
or end > array.length
.public static void quickSort(int start, int end, IntComparator comp, Swapper swap)
start
- the start index to sort.end
- the last + 1 index to sort.comp
- the comparator.swap
- an object that can exchange the positions of two items.IllegalArgumentException
- if start > end
.ArrayIndexOutOfBoundsException
- if start < 0
or end > array.length
.public static void quickSort(char[] array, int start, int end, CharComparator comp)
array
- the char
array to be sorted.start
- the start index to sort.end
- the last + 1 index to sort.IllegalArgumentException
- if start > end
.ArrayIndexOutOfBoundsException
- if start < 0
or end > array.length
.public static void quickSort(double[] array, int start, int end, DoubleComparator comp)
array
- the double
array to be sorted.start
- the start index to sort.end
- the last + 1 index to sort.comp
- the comparison.IllegalArgumentException
- if start > end
.ArrayIndexOutOfBoundsException
- if start < 0
or end > array.length
.Double.compareTo(Double)
public static void quickSort(float[] array, int start, int end, FloatComparator comp)
array
- the float
array to be sorted.start
- the start index to sort.end
- the last + 1 index to sort.comp
- the comparator.IllegalArgumentException
- if start > end
.ArrayIndexOutOfBoundsException
- if start < 0
or end > array.length
.public static void quickSort(int[] array, int start, int end, IntComparator comp)
array
- the int
array to be sorted.start
- the start index to sort.end
- the last + 1 index to sort.comp
- the comparator.IllegalArgumentException
- if start > end
.ArrayIndexOutOfBoundsException
- if start < 0
or end > array.length
.public static void quickSort(long[] array, int start, int end, LongComparator comp)
array
- the long
array to be sorted.start
- the start index to sort.end
- the last + 1 index to sort.comp
- the comparator.IllegalArgumentException
- if start > end
.ArrayIndexOutOfBoundsException
- if start < 0
or end > array.length
.public static <T> void quickSort(T[] array, int start, int end, Comparator<T> comp)
array
- the array to be sorted.start
- the start index to sort.end
- the last + 1 index to sort.comp
- the comparator.IllegalArgumentException
- if start > end
.ArrayIndexOutOfBoundsException
- if start < 0
or end > array.length
.public static <T extends Comparable<? super T>> void quickSort(T[] array, int start, int end)
T
- The type of object.array
- the array.start
- the first index.end
- the last index (exclusive).public static void quickSort(short[] array, int start, int end, ShortComparator comp)
array
- the short
array to be sorted.start
- the start index to sort.end
- the last + 1 index to sort.IllegalArgumentException
- if start > end
.ArrayIndexOutOfBoundsException
- if start < 0
or end > array.length
.public static <T> void mergeSort(T[] array, int start, int end, Comparator<T> comp)
T
- the type of object in the array.array
- the array.start
- first index.end
- last index (exclusive).comp
- comparator object.public static <T extends Comparable<? super T>> void mergeSort(T[] array, int start, int end)
T
- the type of the objects in the array.array
- the array.start
- the first index.end
- the last index (exclusive).public static void mergeSort(byte[] array, int start, int end)
array
- the array.start
- the first index.end
- the last index (exclusive).public static void mergeSort(byte[] array, int start, int end, ByteComparator comp)
array
- the array.start
- the first index.end
- the last index (exclusive).comp
- the comparator object.public static void mergeSort(char[] array, int start, int end)
array
- the array.start
- the first index.end
- the last index (exclusive).public static void mergeSort(char[] array, int start, int end, CharComparator comp)
array
- the array.start
- the first index.end
- the last index (exclusive).comp
- the comparator object.public static void mergeSort(short[] array, int start, int end)
array
- the array.start
- the first index.end
- the last index (exclusive).public static void mergeSort(short[] array, int start, int end, ShortComparator comp)
public static void mergeSort(int[] array, int start, int end)
public static void mergeSort(int[] array, int start, int end, IntComparator comp)
array
- the array.start
- the first index.end
- the last index (exclusive).comp
- the comparator object.public static void mergeSort(long[] array, int start, int end)
array
- the array.start
- the first index.end
- the last index (exclusive).public static void mergeSort(long[] array, int start, int end, LongComparator comp)
array
- the array.start
- the first index.end
- the last index (exclusive).comp
- the comparator object.public static void mergeSort(float[] array, int start, int end)
array
- the array.start
- the first index.end
- the last index (exclusive).public static void mergeSort(float[] array, int start, int end, FloatComparator comp)
array
- the array.start
- the first index.end
- the last index (exclusive).comp
- the comparator object.public static void mergeSort(double[] array, int start, int end)
array
- the array.start
- the first index.end
- the last index (exclusive).public static void mergeSort(double[] array, int start, int end, DoubleComparator comp)
array
- the array.start
- the first index.end
- the last index (exclusive).comp
- the comparator object.public static void mergeSort(int fromIndex, int toIndex, IntComparator c, Swapper swapper)
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
The sorting algorithm is a modified mergesort (in which the merge is omitted if the highest element in the low sublist is less than the lowest element in the high sublist). This algorithm offers guaranteed n*log(n) performance, and can approach linear performance on nearly sorted lists.
fromIndex
- the index of the first element (inclusive) to be sorted.toIndex
- the index of the last element (exclusive) to be sorted.c
- the comparator to determine the order of the generic data.swapper
- an object that knows how to swap the elements at any two indexes (a,b).IntComparator
,
Swapper
Copyright © 2008–2017 The Apache Software Foundation. All rights reserved.