# Class Sorter.MergeSorter

public class MergeSorter
extends Sorter.ASorter

A concrete sorter that uses the Merge Sort method.

##

_tempA
  Temporary array for merging

##

MergeSorter (AOrder)

##

join (Object[], int, int, int)
  Joins sorted A[lo:s-1] and sorted A[s:hi] into A[lo:hi]
merge (Object[], int, int, int)
  Merges the sorted A[lx:mx-1] and the sorted A[mx:rx] into _tempA[lx:rx]
split (Object[], int, int)
  Splits A[lo:hi] into A[lo:s-1] and A[s:hi] where s is the returned value of this function

##

_tempA

    private Object[] _tempA = new Object[1]

  Temporary array for merging.

##

MergeSorter

    public  MergeSorter(AOrder iCompareOp)

  Parameters:
    iCompareOp -

##

merge

    private void merge(Object[] A, int lo, int s, int hi)

  Merges the sorted A[lx:mx-1] and the sorted A[mx:rx] into _tempA[lx:rx].

  Parameters:
    A - A[lx:mx-1] (left array) and A[mx:rx] (right array) are sorted.
    lx - the low index of the left array.
    mx - the low index of the right array, lx < mx <= rx.
    rx - the high index of the right array.

split

    public int split(Object[] A, int lo, int hi)

  Splits A[lo:hi] into A[lo:s-1] and A[s:hi] where s is the returned value of this function. Splits the sub-array in two.

  Parameters:
    A - the array A[lo:hi] to be sorted.
    lo - the low index of A.
    hi - the high index of A.
  Returns:
    (hi-lo)/2 always.

join

    public void join(Object[] A, int lo, int s, int hi)

  Joins sorted A[lo:s-1] and sorted A[s:hi] into A[lo:hi]. This method uses the temporary array to merge the sub-arrays into and copies the data back to the original space.

  Parameters:
    A - A[lo:s-1] and A[s:hi] are sorted.
    lo - the low index of A.
    s -
    hi - the high index of A.