The median of a list of numbers is essentially its middle element after sorting. The same number of elements occur after it as before. Given a list of numbers with an odd number of elements, find the median.
arr = [5, 3, 1, 2, 4];
The sorted array arr' = [1, 2, 3, 4, 5]. The middle element and the median is 3.
findMedian has the following parameter(s):
- int arr[n]: an unsorted array of integers
int: the median of the array
- 1 <= n <= 1000001
- n is odd
- -10000 <= arr[i] <= 10000