I have the following homework assignment in C. I basically need an approach rather than a solution.
We have a 13 x 13 array. In the array, we have a diamond shape that we need to consider. Everything outside this diamond is initialized to -1 (unimportant). Example 5 x 5 array below-
x x 1 x x
x 2 2 2 x
3 3 3 3 3
x 4 4 4 x
x x 5 x x
x=-1
Now in this array, the values we have in the diamond for each entry contains 11 bits. 5 lsb contains one data (hue), and other 6 contains another data (diameter). We need to sort the data row-wise, monotonically for the hue, and then column-wise for the diameter, monotonically.
What would be the most efficient and memory conserving way of doing this? Since we need to conserve this, it's best if the entries are swapped around rather than creating another array. In the end, we will end up with a sorted diamond array (still with the -1s). Thanks a lot in advance guys!
I didn't understand how exactly you want to reorder the elements
row-wise, monotonically for the hue, and then column-wise for the diameter, monotonically
but here are some ideas you might be able to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With