Find median from array of double with given range.

sepknow
sepknow used Ask the Experts™
on
Given an array [1..1000] of double.
Given a range of say 120..820.
How do I find the median value from the given range with Delphi 6?
(Free component recommendation is acceptable).
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
This site explains the basics of the mean, median, and mode.
http://www.purplemath.com/modules/meanmode.htm
However, to answer your question more directly, the median value is the middle one, so all you need to do is find the ones that are #500 and #501 in the list when it is sorted (either in ascending or descending order).  If those are the same, then that is the median (or middle) value.  If those two are different, then the usual custom is to use the average of the two [i.e. (V500 + V501) / 2 ].
Oh, yeah, perhaps the quickest way to do the task is to put the values in a sorted TStringList and then check the YourStringList.Count to see if it is an odd number or an even number.  
If it is an odd number, add 1 and then divide by 2 and use that value.
If it is even, then divide by 2, add that entry and the next one, divide by 2, and, poof!, there you have it.  As my UK friends would say, "Quick as Bob's your uncle!"  (Wahtever that means. ;-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial