You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
683 B

#quicksort is a prime example of an algorithm that is more suited to imperative than functional.
#As it relies on swap in place it can be considered a pathological case for functional programmin
#There are however ways to make it work
#example of some functional approaches to quicksort
#https://www.youtube.com/watch?v=vzfy4EKwG_Y
set js {
function partition(arr, pivotIndex, low, high) {
let partitionIndex = low;
for (let i = low; i< high; i++) {
if (arr[i] < arr[pivotIndex]) {
swap(arr, i, partitionIndex);
partitionIndex++;
}
}
swap(arr, high, partitionIndex);
return partitionIndex;
}
}