comparing numbers to sort then get median value

后端 未结 3 622
无人共我
无人共我 2021-01-19 14:10

Sorting five integers using bitwise or comparison operators can be achieved by first getting the highest number then the second highest then the third and so on.

Her

3条回答
  •  隐瞒了意图╮
    2021-01-19 14:50

    One way to think about it is to consider the 10 comparison operations between the 5 numbers as your binary inputs. Then you have options:

    1. Draw a 10-input Karnaugh map and simplify the logic where possible.
    2. Build a 10-bit number as an index into a table.

    Some of the possibilities will never occur, so I'm sure there's some simplification possible. For instance if (a>b) and (b>c) then (a>c) will always be true. Which will help with approach #1 and generates an error case in approach #2.

提交回复
热议问题