Use any linear time sort, but the comparisons (a,b)>(c,d) will be replaced by ac>bd (where (u,v) denotes the fraction u/v, and also I have assumed that a, b, c and d are all positive).

Or if you are not constained by the size of your integer type multiply all the numbers by N!, then sort.

RonL