C++ c++;宽度优先搜索中迭代器和指针的使用
当使用较大的数组维度时,我已将程序的终止隔离为始终在2D顶点数组的宽度优先搜索期间终止: 我的顶点类已声明C++ c++;宽度优先搜索中迭代器和指针的使用,c++,pointers,iterator,breadth-first-search,C++,Pointers,Iterator,Breadth First Search,当使用较大的数组维度时,我已将程序的终止隔离为始终在2D顶点数组的宽度优先搜索期间终止: 我的顶点类已声明 class Vertex{ public: int i, j; std::set<Vertex*> adj; //references to adjacent vertices (max of 4) //used in solving maz
class Vertex{
public:
int i, j;
std::set<Vertex*> adj; //references to adjacent vertices (max of 4)
//used in solving maze
bool visited;
std::list<Vertex> path; //stores path from start vertex to this vertex
Vertex();
~Vertex();
//end constructors
void setPos(int row, int col);
/** for iterators */
typedef std::set<Vertex*>::iterator iterator;
iterator begin();
iterator end();
};//END class Vertex
所以我怀疑这是我在指针/迭代器的使用等方面做错了什么,就像我在上面的while循环中的一行“(*it)->path.push_back(**it);”,因为最后打印的是1,然后它终止,但它只在使用更大的数组维度时发生
有人能帮我弄清楚发生了什么吗?
std::list<Vertex> path; //stores path from start vertex to this vertex
std::列表路径//存储从起始顶点到该顶点的路径
到
std::列表路径//存储从起始顶点到该顶点的路径
工作得很好。应该知道我浪费了多少资源,谢谢@uesp 在多大的阵列大小下会遇到问题?您是否检查过内存是否不足?由于
path
按值存储顶点
,随着顶点数量和顶点之间连接的增加,我预计内存使用量会迅速增加。向量通常比列表快。
...
1
2
1
2
1
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
make: *** [makeExec] Error 3
std::list<Vertex> path; //stores path from start vertex to this vertex
std::list<Vertex*> path; //stores path from start vertex to this vertex