SIGBART ERROR vector< list< myClass> >

编程入门 行业动态 更新时间:2024-10-28 06:21:17
本文介绍了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;

本文发布于:2023-11-11 11:50:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:vector   amp   SIGBART   ERROR   lt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!