c++ list的迭代器问题,求帮助
烟云觅渡 2016-12-31 08:21:00 Program: C:\windows\system32\MSVCP110D.dll
File: d:\visual studio 2012\vs安装文件\vc\include\list
Line: 210
Expression: list iterator not dereferencable
For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.
下面是代码:
void EctractionOfTreeTrunk(list<Point> *SP,list<Point> *O,list<Point> *R,list<list<Point>> *trees,double *HT,double *VT,double *h1,double *h2) //SP是种子集,操作完这一步之后需要把种子集清空
{
double TreeHight(list<Point> l);
list<Point> Tree,N,Bush; //N用来收集不是treei的点
list<Point> lower_dmin3;
double dmin,dmin1,dmin2,dmin3,H;
Point n0;
for(list<Point>::iterator t=SP->begin();t!=SP->end();)
{
if(t->z>*h2)
{
O->push_back(*t);
t=SP->erase(t);
}
else
{
cout<<"Begin to create a new tree!"<<endl;
Tree.push_back(*t);
n0.Copy(t->insertn0());
N.push_back(n0);
for(list<Point>::iterator it=O->begin();it!=O->end();)
{
if(it->z<*VT)
{
dmin=it->TwoDistoTree(Tree); //这里的Tree是指当前的Tree
if(dmin<=*HT)
{
Tree.push_back(*it);
it=O->erase(it);
}
else
{
N.push_back(*it);
it++;
}
}
else
{
dmin1=it->TwoDistoTree(Tree);
if(dmin1<*HT)
{
dmin2=it->ThreeDistoTree(Tree);
for(list<Point>::iterator mm=N.begin();mm!=N.end();mm++)
{
if(mm->z<it->z)
lower_dmin3.push_back(*mm);
}
dmin3=it->ThreeDistoTree(lower_dmin3);
if(dmin2<dmin3)
{
Tree.push_back(*it);
it=O->erase(it);
}
else
{
R->push_back(*it);
it=O->erase(it);
}
}
else
{
it++;
N.push_back(*it);
}
}
}
cout<<"到此处完成了一棵树的分割."<<endl;
cout<<"当前树的大小:"<<Tree.size()<<endl;
cout<<"current O size:"<<O->size()<<endl;
H=TreeHight(Tree);
cout<<"当前树高:"<<H<<endl;
if(H<*h1) //h1是树干长度限制
{
for(list<Point>::iterator f=Tree.begin();f!=Tree.end();)
{
Bush.push_back(*f);
f=Tree.erase(f);
}
}
else //这里是H>*h1的情况。
{
trees->push_back(Tree);
Tree.clear();
N.clear();
}
t++;
cout<<"当前O的大小:"<<O->size()<<" 树集的大小"<<trees->size()<<endl;
cout<<"ConstructTree finished!!"<<endl;
}
}
if(!SP->empty()) SP->clear();
}