Code4Food
2020-5-15 08:39:14
Simplest way is to create an array of numbers in [0,.. 2^n-1] and then use qsort() to sort the numbers by number of bits and value.
Code4Food
2020-5-15 08:57:30
One may also use recursion, of course. The code should be very simple and readable Due to O(2^n) output size, stack overflow is not really an issue.