|Did you know ...||Search Documentation:|
|Pack dynworks -- prolog/quicksort.pl|
An implementation of the classic Quicksort sorting algorithm on generic lists.
Quicksort works by selecting a 'pivot' element from the list to be sorted and
partitioning the other elements into two sublists, according to whether they are
less than or greater than the pivot.The sublists are then sorted recursively.
For a description of the quicksort algorithm, see
This implementation takes as input a
comparator. This is a predicate able to
perform a comparison between any two elements of the input list as parameters,
and return a negative number, zero, or a positive number, to indicate whether the
first parameter is smaller than, equal to, or greater than the second parameter,
<Comparator>(+ValueX, +ValueY, -Result:number) is det where Result is unified with a) 0 (zero) - ValueX is equal to ValueY b) a negative number - ValueX is less than ValueY c) a positive number - ValueX is greater than ValueY
The criteria that will determine the results of the comparisons are entirely up to Comparator, and as such it must be able to handle the values it will receive. Nothing is done if List has less than 2 elements.