What seems to be the error? it keeps returning segmentation fault 11. this is supposed to be a solution to a maze using DFS. ............................... ...............................
std::vector<MazeNode> solveDFS(Maze &a_maze){
MazeNode* nextNode = a_maze.getFirstNode();
std::vector<MazeNode> nodes;
std::stack<MazeNode*> nodesPtr;
nextNode->setVisited();//set origin as visited
nodesPtr.push(a_maze.getFirstNode());//add origin to stack
nodes.push_back(*a_maze.getFirstNode());//first node added to vector
//cout << a_maze.getFirstNode() << endl;
while(!nodesPtr.empty()){
MazeNode* TopStack = nodesPtr.top();
if(canTravel(TopStack->getDirectionNode(directions::NORTH))){
nextNode = TopStack->getDirectionNode(directions::NORTH);
nextNode->setVisited();
nodesPtr.push(nextNode);
nodes.push_back(*nextNode);
}
else if(canTravel(TopStack->getDirectionNode(directions::WEST))){
nextNode = TopStack->getDirectionNode(directions::WEST);
nextNode->setVisited();
nodesPtr.push(nextNode);
nodes.push_back(*nextNode);
}
else if(canTravel(TopStack->getDirectionNode(directions::SOUTH))){
nextNode = TopStack->getDirectionNode(directions::SOUTH);
nextNode->setVisited();
nodesPtr.push(nextNode);
nodes.push_back(*nextNode);
}
else if(canTravel(TopStack->getDirectionNode(directions::EAST))){
nextNode = TopStack->getDirectionNode(directions::EAST);
nextNode->setVisited();
nodesPtr.push(nextNode);
nodes.push_back(*nextNode);
}
else{
nodesPtr.pop();
}
}
return nodes;
}
Aucun commentaire:
Enregistrer un commentaire