dev/vala/array_sort/array_sort.vala

56 lines
1.0 KiB
Vala

/**
* Bounds of the ``ATable`` to split.
*/
public struct SplitLimit {
/**
* First column index [0; last].
*/
uint first;
/**
* Last column index [first; ncols - 1].
*/
uint last;
/**
* Maximum of columns per page [1; ncols].
*/
uint max_cols;
}
void print_list (List<SplitLimit?> array) {
for (var i = 0; i < array.length(); ++i) {
stdout.printf ("%lu %lu %lu\n", array.nth(i).data.first,
array.nth(i).data.last, array.nth(i).data.max_cols);
}
}
void main () {
var array = new List<SplitLimit?> ();
SplitLimit lim = { 9, 11, 3 };
array.append (lim);
lim = { 2, 6, 2 };
array.append (lim);
lim = { 13, 16, 1 };
array.append (lim);
//array.append ("ccc");
//array.append ("aaa");
//array.append ("bbb");
print_list (array);
stdout.puts ("--------\n");
array.sort ((a, b) => {
stdout.printf ("a.first=%lu\n", a.first);
if (a.first < b.first) return -1;
if (a.first > b.first) return 1;
return 0;
});
stdout.puts ("--------\n");
print_list (array);
}