import { compare } from "@thi.ng/compare/compare";
import { swap } from "./swap.js";
function quickSort(arr, _cmp = compare, _swap = swap, start = 0, end = arr.length - 1) {
  if (start < end) {
    const pivot = arr[start + (end - start >> 1)];
    let s = start - 1;
    let e = end + 1;
    while (true) {
      do {
        s++;
      } while (_cmp(arr[s], pivot) < 0);
      do {
        e--;
      } while (_cmp(arr[e], pivot) > 0);
      if (s >= e) break;
      _swap(arr, s, e);
    }
    quickSort(arr, _cmp, _swap, start, e);
    quickSort(arr, _cmp, _swap, e + 1, end);
  }
  return arr;
}
export {
  quickSort
};
