sort
fn sort<T: Ord>(Vec<T> arr) -> Vec<T> Import
Source: use collections::{sort}; src/collections.hy Returns a sorted copy of arr, in ascending order.
The sort is stable (equal elements keep their order) and takes O(n log n)
time. arr itself is not changed. Elements need Ord; strings compare by
their UTF-8 bytes, so "B" sorts before "a".
Parameters#
| Name | Type |
|---|---|
arr | Vec<T> |
Returns#
Vec<T>
Contracts#
Checked according to --contracts (see Contracts).
ensures result.len() == arr.len()
Examples#
use collections::{sort};
use tests::assert;
let xs: Vec<int> = [3, 1, 2];
let s = sort(xs);
assert!(s[0] == 1 && s[2] == 3);
assert!(xs[0] == 3);
let words: Vec<string> = ["pear", "Apple", "fig"];
assert!(sort(words)[0] == "Apple");
See also#
Ordsort_by: Returns a copy ofarrsorted by the valuekeygives each element, in ascending order.reverse: Returns a copy ofarrin reverse order.collect_ints: Returns the values of the rangea..bas aVec<int>.collect_ints_inclusive: Returns the values of the inclusive rangea..=bas aVec<int>.