Well, if it's efficiency you're concerned about... rub hands together Since you only need the top k values where k << N , you don't need to sort the whole list. O(N log N). You can use
Partial selection sort O(Nk)
max-heap of k elements. O(N + k log N)
As for the compare function did you try something like qsort translated to lite-c?