I've tried to do some sorting with GLib's GenericArray
, Slist
, List
. Sorting with sort_with_data
works as expected, but when I've tried Glib's Array
it doesn't work, or rather it does something different!
This is my sort function for integers:
[indent=4]
init
var a = new Array of int
for i in new array of int = {3, 2, 1, 5, 7}
a.append_val (i)
a.sort_with_data (my_func)
for var i = 0 to (a.length - 1)
stdout.printf ("%d, ", a.index (i))
// 3, 2, 1, 5, 7,
stdout.putc ('\n')
a.sort (my_func)
for var i = 0 to (a.length - 1)
stdout.printf ("%d, ", a.index (i))
// 3, 2, 1, 5, 7,
def my_func (a: int, b: int): int
return a - b
the output is 3, 2, 1, 5, 7,
I don't know what's wrong. Please don't tell me to use Gee! my question is sort Array of int Thanks!