1. Engineering
  2. Computer Science
  3. let a b unsorted e an array of n elements...

Question: let a b unsorted e an array of n elements...

Question details


Let A b unsorted e an array of n elements. Write a template function that takes an array or type <class T and its length as parameters and returns the median (a median is the middle value, so that there are just as many values above the median as those that are below the median) of the array. Assume the operator , >, +, and/are defined for the class T. If n is odd, the median is the middle vale, if n is even, the median is the average of the middle two values. Examples: The median of 1934 6 is 4 since 1 and 3 are less than 4 and 6 and 9 are greater than 4. The median of 1 9 3 62 is (3+4)y2 since half the numbers (1.2, 3) are less and half (4,6, 9) are greater than 3.5.
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution