I give below a sample program that is somewhat similar to the one in Max S.'s response. To help the OP advance his knowledge and understanding, I have made a number of changes. I have:
a) changed the call by const reference to call by value, since sort is going to want to change the order of the elements in your vector, (EDIT: I just saw that Rob Kennedy also said this while I was preparing my post)
b) replaced size_t with the more appropriate vector<int
>::size_type (actually, a convenient synonym of the latter),
c) saved size/2 to an intermediate variable,
d) thrown an exception if the vector is empty, and
e) I have also introduced the conditional operator (? :).
Actually, all of these corrections are straight out of Chapter 4 of "Accelerated C++" by Koenig and Moo.
double median(vector<int> vec)
{
typedef vector<int>::size_type vec_sz;
vec_sz size = vec.size();
if (size == 0)
throw domain_error("median of an empty vector");
sort(vec.begin(), vec.end());
vec_sz mid = size/2;
return size % 2 == 0 ? (vec[mid] + vec[mid-1]) / 2 : vec[mid];
}