Need help with sorting a 32 bit string
I think viewing this as sorting is a complicated way to address this problem. Shuffling the bits all the way in Verilog would certainly be a pain.

Unless I did not uderstood the problem well, it seems to boil down to counting the bits that are set to 1, and outputting a string that has this number of 1 to the right. I think this would be a more appropriate way to solve this problem in Verilog.

The most difficult part here is counting the bits. How to do it was asked here and here. A simple way is to add all the bits (and trust the optimizer for generating an efficient way of combining the logic).

Then, serially output the appropriate number of 0 followed by the appropriate number of 1 (depending on the result).