quickSort | R Documentation |
Implements the quicksort algorithm for partial orderings based on pairwise comparisons.
quickSort(x, f = greaterThan, ..., random = TRUE)
x |
A list or vector of items to be sorted. |
f |
A function on two arguments for comparing elements of |
... |
other arguments to |
random |
logical - should a random pivot be chosen? (this is recommended) Otherwise middle element is used. |
Implements the usual quicksort algorithm, but may return the same positions
for items which are incomparable (or equal). Does not test the validity of
f
as a partial order.
If x
is a numeric vector with distinct entries, this behaves just
like rank
.
Returns an integer vector giving each element's position in the order (minimal element(s) is 1, etc).
Output may not be consistent for certain partial orderings (using random pivot), see example below. All results will be consistent with a total ordering which is itselft consistent with the true partial ordering.
f
is not checked to see that it returns a legitimate partial order,
so results may be meaningless if it is not.
Robin Evans
https://en.wikipedia.org/wiki/Quicksort.
order
.
set.seed(1) quickSort(powerSet(1:3), f=subsetOrder) quickSort(powerSet(1:3), f=subsetOrder) # slightly different answers, but both correposnding # to a legitimate total ordering.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.