refactoring: use a list_add_sorted() + list_map() to avoid too much work

Otherwise we build a list in O(1), then create an array
where we copy the entries in O(n), Then we sort the array in O(nlog(n)).

Here we directly build the array sorted, then "display" it, in O(2n)