quickSort static method

List quickSort(
  1. List list
)

Implementation of the quick sort algorithm

Implementation

static List quickSort(List list) {
  if (list.length <= 1) {
    return list;
  }

  var pivot = list[0];
  var less = [];
  var more = [];
  var pivotList = [];

  list.forEach((var element) {
    if (element.compareTo(pivot) < 0) {
      less.add(element);
    } else if (element.compareTo(pivot) > 0) {
      more.add(element);
    } else {
      pivotList.add(element);
    }
  });

  less = quickSort(less);
  more = quickSort(more);

  less.addAll(pivotList);
  less.addAll(more);
  return less;
}