i find a bug
helper.cpp
extern void insert_element(multiset
if(m.empty() || x < *(m.begin()))
M.insert(x);
else
m.insert(x);
if(m.size() > M.size() + 1){
multiset<double>::iterator i;
i = m.begin();
m.erase(m.begin());
M.insert(*i);
}
else if(M.size() > m.size() + 1){
multiset<double, std::greater<double> >::iterator i;
i = M.begin();
M.erase(M.begin());
m.insert(*i);
}
}
i = M.begin();
M.erase(M.begin());
m.insert(*i)
this code here , after M.erase(M.begin()); iterator i is null;
same code also in remove_element() function.
Could you please provide the sample input that is causing you to get an error?
As it is written now the code checks to make sure that M is not empty. Thus you shouldn't get any error.
any input will lead to this ,this is not about M is empty or not , this is c++ stl use fault . you can debug this function in gdb linux or dev c++ in windows,i have do it several times. thank you .
i = M.begin(); M.erase(M.begin()); m.insert(_i);-------------------->_i is a random double , because i is Invalid after M.erase(M.begin()); i switch like this , i = M.begin(); m.insert(*i); M.erase(M.begin());
Thanks, that slipped my mind. I'll make the correction.