Example: Insert sorted

public static int main (string[] args) {
Sequence<string> seq = new Sequence<string> ();
seq.append ("1. Lorem");
seq.append ("2. ipsum");
seq.append ("4. sit");
seq.append ("5. amet");

seq.insert_sorted ("3. dolor", (a, b) => {
return strcmp (a, b);
});

// Output:
// ``1. Lorem``
// ``2. ipsum``
// ``3. dolor``
// ``4. sit``
// ``5. amet``
seq.foreach ((item) => {
print ("%s\n", item);
});

return 0;
}

 valac --pkg glib-2.0 GLib.Sequence.insert_sorted.vala

See:




2022 vala-language.org