SultanC
  1. Home
  2. Examples
  3. Collections

Sorting numbers and text, then binary-searching the sorted vector

collections/sorting.sn
// Sorting numbers and text, then binary-searching the sorted vector.
import std.io.println;
import std.text.number;
import std.text.transform;
import std.collections.sort;

def main(): int {
    let numbers: mutable vector int = [42, 7, 19, 3, 88, 1];
    sort_int(&mutable numbers);
    let names: mutable vector string = ["noor", "adam", "zaid", "huda"];
    sort_texts(&mutable names);
    let comma: string = ", ";
    println(join(&names, &comma));
    match binary_search_int(&numbers, 19) with
    | option.some(index) -> { println(uint_to_text(index)); }
    | option.none -> { println("missing"); };
    println(int_to_text(numbers[0]));
    return 0;
}

Run it

With the interpreter, without compiling:

./build/sultanc run examples/en/collections/sorting.sn

Or compile it to an executable:

./build/sultanc examples/en/collections/sorting.sn -o build/example && ./build/example

Source on GitHub   All examples