Sort
#func Sort<T>(v: Vector<T>)Sorts the vector in ascending order with an introsort: n log n on any input, not stable. The default choice for sorting. Strings are compared byte by byte.
import sort
func main:
mut numbers := Vector {} as Vector<int>
defer numbers.Free()
each n in [5, 3, 9, 1, 7]:
numbers.Push(n)
end
println sort.IsSorted(numbers)
ordered := sort.Sorted(numbers)
println ordered, numbers
sort.Sort(numbers)
println numbers, sort.IsSorted(numbers)
sort.SortDesc(numbers)
println numbers
sort.Reverse(numbers)
println numbers, sort.Min(numbers), sort.Max(numbers)
sort.Swap(numbers, 0, 4)
println numbers
endfalse [1, 3, 5, 7, 9] [5, 3, 9, 1, 7] [1, 3, 5, 7, 9] true [9, 7, 5, 3, 1] [1, 3, 5, 7, 9] 1 9 [9, 3, 5, 7, 1]