If your data is static, those you could precalcate it and do not insert new elements - it’s simplier to use vector , sort it , and access median just by index in O(1)
vector data;
// fill data
std::sort(data.begin(), data.end());
auto median = data[data.size() / 2];