Radix Sort Algorithm

前端 未结 4 1283
时光说笑
时光说笑 2021-01-14 07:39

I have been given some algorithms to reverse engineer. The algorithm below is a radix sort, but I am very confused about what is actually happening in the code.

I\'

4条回答
  •  情深已故
    2021-01-14 07:50

    Algorithms are where you should start learning about programming!

    To see what an undocumented piece of code does, you may need to adopt a pseudo-language to put the work into an english mathematics statement.

    For example, you note that this snippet should only work for 8-bit numbers (the outer loop on bit). The rough description is that the array elements are "sorted" into two buckets depending on whether the bit in position "bit" is a zero or a one -- starting with the bit in the lease significant position. The original array is then reordered with "ones" coming before "zeros" .. which should order the array from largest to smallest.

    You would be well served to look up radix sort algorithms, and start with that rather than starting with code.

提交回复
热议问题