How do I calculate the “median of five” in C#?

后端 未结 10 2062
遇见更好的自我
遇见更好的自我 2020-12-04 22:05

The median of five is sometimes used as an exercise in algorithm design and is known to be computable using only 6 comparisons.

What is the best way

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-04 23:01

    For completeness, the question is a specific case of a sorting network, which Knuth (Art of Computer Programming, vol 3) covers in great detail. The classic paper by K.E. Batcher on the subject is brief and worth reading.

提交回复
热议问题