
Recursion Problem
I am unable to write a recursive function that takes in a vector of numbers and returns the median.
double median (vector <double> vec)
{
typedef vector<double> :: size_type vec_sz;
vec_sz size = vec.size();
if (size==0)
return false;
sort(vec.begin(), vec.end());
vec_sz mid = size/2;
return size%2 ==0 ?(vec[mid]+vec[mid1])/2 : vec[mid];
}
Call the recursive function on the list with the last element removed.This gives you the median of the previous list. Now, with that knowledge, how do you find the median of the entire list?.
Can any one help me with the above problem
Thanking you in advance for your reply and time