SIGBART ERROR vector< list< myClass> > [英] SIGBART ERROR vector<list<myClass> >

查看:162
本文介绍了SIGBART ERROR vector< list< myClass> >的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我们调用这个函数时,我缩小了它的范围。

  bool Node :: isEdgeConnected(Node vertex1,Node vertex2){

//我不确定这是否正确复制此向量的方法< list>
vector< list< Node> > myEdgeList = * edgeList; // edgeList是Node的私有数据成员

vector< list< Node> > :: iterator it;
cout<< myEdgeList.size(); (it = myEdgeList.begin(); it!= myEdgeList.end(); it ++){
list< Node>(

$ b)边缘;
edge = * it;
节点placeNode = edge.front();

cout<< placeNode.getNodeId()<< endl;
list< Node> :: iterator eIt;
for(eIt = edge.begin(); eIt!= edge.end(); eIt ++){
节点placeNode1,placeNode2;
placeNode1 = edge.front();
placeNode2 = * eIt;

cout<< placeNode1.getNodeId()<< << placeNode2.getNodeId()<< ENDL;
if(placeNode1.getNodeId()== vertex1.getNodeId()&&
placeNode2.getNodeId()== vertex2.getNodeId()){
return true;
}
}
}
返回false;


任何帮助将不胜感激。

解决方案

很可能您的代码在节点placeNode = edge.front(); 需要检查 edge 是否为空

  if(edge。空()){
继续;
}
节点placeNode = edge.front();

顺便说一句, isEdgeConnected()要检查 edgeList 中的节点值,不需要复制所有元素。如果你的 edgeList 很大,那么拷贝会很贵。

例如,你可以迭代 edgeList ,并且 ++ iter 比iter ++效率更高,请参阅 this

  for(vector< list< Node>> :: iterator it = edgeList-> begin(); 
it!= edgeList-> end(); ++ it){
}


I cannot find the reason why my program throws a SIGBART error.

I've narrowed it down when this function is called.

bool Node::isEdgeConnected(Node vertex1, Node vertex2){

//I'm not sure if this is the right way to copy this vector <list>
vector<list<Node> > myEdgeList = *edgeList;//edgeList is a private data member of Node

vector<list<Node> >::iterator it;
cout << myEdgeList.size();


for (it = myEdgeList.begin(); it != myEdgeList.end(); it++) {
    list<Node> edge;
    edge = *it;
    Node placeNode = edge.front();

    cout <<placeNode.getNodeId()<<endl;
    list<Node>::iterator eIt;
    for (eIt = edge.begin(); eIt != edge.end(); eIt++) {
        Node placeNode1, placeNode2;
        placeNode1 = edge.front();
        placeNode2 = *eIt;

        cout << placeNode1.getNodeId() << " " << placeNode2.getNodeId()<<endl;
        if(placeNode1.getNodeId() == vertex1.getNodeId() &&
           placeNode2.getNodeId() == vertex2.getNodeId()){
            return true;
        }
    }
}
return false;

}

Any help would be appreciated.

解决方案

Most likely your code fails in line Node placeNode = edge.front();, you need to check if edge is empty or not

if (edge.empty()){
   continue;
}
Node placeNode = edge.front();

BTW, isEdgeConnected() function is just to check node value inside edgeList, you don't need to copy all elements. if your edgeList is big, copy will be expensive.

For example, you could iterate edgeList directly, also ++iter is more efficient than `iter++, see this

for (vector<list<Node> >::iterator it = edgeList->begin();                                       
     it != edgeList->end(); ++it) {
}

这篇关于SIGBART ERROR vector&lt; list&lt; myClass&gt; &GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆