I can't help much with Genie, but in Vala it would be:
private static int main (string[] args) {
string[] datas = new string[] {
"cold", "z", "bpples", "pallalala", "apples", "xccv"
};
GLib.qsort_with_data<string> (datas, sizeof(string), (a, b) => GLib.strcmp (a, b));
return 0;
}
Basically, the key is GLib.qsort_with_data
. You can also use Posix.qsort
like apmasell mentioned, but it's a bit more difficult.
Like apmasell and txasatonga mentioned, you could use a datatype from libgee, but unless you're already using libgee you might want to go with something from glib instead. In this case, GLib.GenericArray
would be a good fit. In Vala, it would look like this:
private static int main (string[] args) {
GLib.GenericArray<string> datas = new GLib.GenericArray<string> ();
datas.add ("cold");
datas.add ("z");
datas.add ("pallalala");
datas.add ("apples");
datas.add ("xccv");
datas.sort (GLib.strcmp);
return 0;
}
One very nice thing about GLib.GenericArray
is that it uses a C array as its underlying storage. If you are using regular arrays in other places in your code you can access the underlying array using the GLib.GenericArray.data
field and potentially avoid copying the entire array. And, of course, it also doesn't force a dependency on libgee.
Finally, your choice of variable name… 'data' is plural, the singular of 'data' is 'datum'. I only bring it up so I have an excuse to post this:
