public class MergeSorter extends java.lang.Object
Constructor and Description |
---|
MergeSorter() |
Modifier and Type | Method and Description |
---|---|
private static <E> void |
merge(E[] a,
int from,
int mid,
int to,
java.util.Comparator<? super E> comp)
Merges two adjacent subranges of an array
|
private static <E> void |
mergeSort(E[] a,
int from,
int to,
java.util.Comparator<? super E> comp)
Sorts a range of an array, using the merge sort
algorithm.
|
static <E> void |
sort(E[] a,
java.util.Comparator<? super E> comp)
Sorts an array, using the merge sort algorithm.
|
public MergeSorter()
public static <E> void sort(E[] a, java.util.Comparator<? super E> comp)
a
- the array to sortcomp
- the comparator to compare array elementsprivate static <E> void mergeSort(E[] a, int from, int to, java.util.Comparator<? super E> comp)
a
- the array to sortfrom
- the first index of the range to sortto
- the last index of the range to sortcomp
- the comparator to compare array elementsprivate static <E> void merge(E[] a, int from, int mid, int to, java.util.Comparator<? super E> comp)
a
- the array with entries to be mergedfrom
- the index of the first element of the
first rangemid
- the index of the last element of the
first rangeto
- the index of the last element of the
second rangecomp
- the comparator to compare array elements