iterator not dereferencable .#include "intset.h"#include #include using namespace std;typedef std::set set_int;void IntSet::insert(int n){set_int::insert(n);}bool IntSet::IsEqual(IntSet s1){set::iterator ita,itb;ita= set_int::begin();itb=s1.begin();i

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 06:26:44
iterator not dereferencable .#include

iterator not dereferencable .#include "intset.h"#include #include using namespace std;typedef std::set set_int;void IntSet::insert(int n){set_int::insert(n);}bool IntSet::IsEqual(IntSet s1){set::iterator ita,itb;ita= set_int::begin();itb=s1.begin();i
iterator not dereferencable .
#include "intset.h"
#include
#include
using namespace std;
typedef std::set set_int;
void IntSet::insert(int n){
set_int::insert(n);
}
bool IntSet::IsEqual(IntSet s1){
set::iterator ita,itb;
ita= set_int::begin();
itb=s1.begin();
if( set_int::size()!=s1.size())
return false;
for(;ita!=set_int::end()&&itb!=s1.end();ita++,itb++){
if((*ita)!=(*itb))
return false;
}
return true;
}
//求s1 与s2 的并
IntSet IntSet::incorporate2(IntSet s1,IntSet s2){
IntSet ss;
set::iterator it;
for(it=s1.begin();it!=s1.end();it++)
ss.insert(*it);
for(it=s2.begin();it!=s2.end();it++)
ss.insert(*it);
return ss;
}
//求s1 与s2 的交
IntSet IntSet::union2(IntSet s1,IntSet s2){
IntSet ss;
set::iterator ita,itb;
ita=s1.begin();
itb=s2.begin();
while(ita =s1.end()&&itb =s2.end()){
while(*ita>*itb&&ita =s1.end()&&itb =s2.end())
itb++;
if(*ita==*itb&&ita =s1.end()&&itb =s2.end()){
ss.insert(*ita);
ita++; //此处出错!
itb++; //此处出错!到达end时没有跳出循环
}
while(*ita

iterator not dereferencable .#include "intset.h"#include #include using namespace std;typedef std::set set_int;void IntSet::insert(int n){set_int::insert(n);}bool IntSet::IsEqual(IntSet s1){set::iterator ita,itb;ita= set_int::begin();itb=s1.begin();i
while(*ita>*itb&&ita !=s1.end()&&itb !=s2.end())
itb++;
if(*ita==*itb&&ita !=s1.end()&&itb !=s2.end()){
ss.insert(*ita);
ita++; //此处出错!
itb++; //此处出错!到达end时没有跳出循环
}
while(*ita*itb&&ita !=s1.end()&&itb !=s2.end())
itb++;
else if(*ita==*itb&& ita !=s1.end()&& itb !=s2.end()){
ss.insert(*ita);
ita++; //此处出错!
itb++; //此处出错!到达end时没有跳出循环
}
else if (*ita