Learn R Programming

rgp (version 0.4-1)

insertionSort: Sorting algorithms for vectors and lists

Description

These algorithms sort a list or vector by a given order relation (which defaults to <=< code="">). insertionSort is a stable O(n^2) sorting algorithm that is quite efficient for very small sets (less than around 20 elements). Use an O(n*log(n)) algorithm for larger sets.

Usage

insertionSort(xs, orderRelation = NULL)

Arguments

xs
The vector or list to sort.
orderRelation
The orderRelation to sort xs by (defaults to `<=`< code="">). This relation by should reflexive, antisymetric, and transitive.

Value

The vector or list xs sorted by the order relation orderRelation.