sort_iter


Description:

public void sort_iter (SequenceIterCompareFunc<G> func)

Like sort, but uses a SequenceIterCompareFunc instead of a CompareDataFunc as the compare function

cmp_func is called with two iterators pointing into this. It should return 0 if the iterators are equal, a negative value if the first iterator comes before the second, and a positive value if the second iterator comes before the first.

Example: Sort a single value:

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

bool asc = true;
seq.sort_iter ((a, b) => {
return (asc)? strcmp (a.get (), b.get ()) : strcmp (b.get (), a.get ());
});

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

return 0;
}

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

Parameters:

this

a Sequence

cmp_data

user data passed to cmp_func

cmp_func

the function used to compare iterators in the sequence