heapSort static method

List heapSort(
  1. List a
)

Implementation of the heap sort algorithm

Implementation

static List heapSort(List a) {
  var count = a.length;

  var start = (count - 2) ~/ 2;

  while (start >= 0) {
    _sink(a, start, count - 1);
    start--;
  }

  var end = count - 1;
  while (end > 0) {
    var tmp = a[end];
    a[end] = a[0];
    a[0] = tmp;

    _sink(a, 0, end - 1);

    end--;
  }
  return a;
}