mergeSort method

void mergeSort({
  1. int start = 0,
  2. int? end,
  3. Comparator<E>? comparator,
})

Sorts this list between start (inclusive) and end (exclusive) using the merge sort algorithm.

If comparator is omitted, this defaults to calling Comparable.compareTo on the objects. If any object is not Comparable, this throws a CastError.

Merge-sorting works by splitting the job into two parts, sorting each recursively, and then merging the two sorted parts.

This takes on the order of n * log(n) comparisons and moves to sort n elements, but requires extra space of about the same size as the list being sorted.

This merge sort is stable: Equal elements end up in the same order as they started in.

Implementation

void mergeSort({int start = 0, int? end, Comparator<E>? comparator}) {
  _mergeSort(this, start: start, end: end, compare: comparator);
}