nth_element (myvector.begin(), myvector.begin() + myvector.size() / 2, myvector.end());
C++ (Qt)void median_split( double * data, // data array int start, // start index in array int end, // end index in array int median ) // desired median index{ int left = start; int right = end; while (right > left) { double v = data[right]; int i = left - 1; int j = right; for (;;) { while (data[++i] < v) ; while (data[--j] > v && j > left) ; if (i >= j) break; std::swap(data[i], data[j]); } std::swap(data[i], data[right]); if (i >= median) right = i - 1; if (i <= median) left = i + 1; }}
median_split(double* data, // data array int start, // start index in array int end, // end index in array int median){ nth_element(data + start, data + median, data + end + 1);}