BreakoutDetection icon indicating copy to clipboard operation
BreakoutDetection copied to clipboard

i find a bug

Open liangshaopeng opened this issue 11 years ago • 5 comments

helper.cpp

liangshaopeng avatar Nov 26 '14 05:11 liangshaopeng

extern void insert_element(multiset& m, multiset<double, std::greater >& M, double x){

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.

liangshaopeng avatar Nov 26 '14 05:11 liangshaopeng

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.

putnam120 avatar Nov 26 '14 21:11 putnam120

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 .

liangshaopeng avatar Nov 27 '14 02:11 liangshaopeng

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());

liangshaopeng avatar Nov 27 '14 02:11 liangshaopeng

Thanks, that slipped my mind. I'll make the correction.

putnam120 avatar Nov 27 '14 03:11 putnam120