functionsort
Sorts elements in a vector using the quick sort algorithm
Information
Syntax
(B, I) = sort (A, first, last);
Description
Vector B contains the elements of vector A sorted by increasing values between indices first and last.
Vector I contains the indices of vector A such that I[i] = j means that B[i] = A[j].
First and last are optional. If first is omitted, then first = 1. If last is omitted, then last equals the size of A.
Examples
(B, I) = sort ({1.3, 1.2, 7.4, 3.6, 20.9, 0, -6.7, -100, 5, 0.1});
returns
B = { -100, -6.7, 0, 0.1, 1.2, 1.3, 3.6, 5, 7.4, 20.9 };
I = { 8, 7, 6, 2, 1, 4, 9, 3, 5 };
(B, I) = sort({1.3, 1.2, 7.4, 3.6, 20.9, 0, -6.7, -100, 5, 0.1}, 2, 7);
returns
B = { 1.3, 1.2, -6.7, 0, 3.6, 7.4, 20.9, -100, 5, 0.1 };
I = { 1, 2, 7, 6, 4, 3, 5, 8, 9, 10 };Inputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real[:] | A | ||
| Integer | first | 1 | |
| Integer | last | size(A, 1) |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real[size(A, 1)] | B | ||
| Integer[size(A, 1)] | I |