本文整理汇总了C++中GraphNode::SetIsVisited方法的典型用法代码示例。如果您正苦于以下问题:C++ GraphNode::SetIsVisited方法的具体用法?C++ GraphNode::SetIsVisited怎么用?C++ GraphNode::SetIsVisited使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GraphNode
的用法示例。
在下文中一共展示了GraphNode::SetIsVisited方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SearchDFS
bool Graph::SearchDFS(GraphNode* start, GraphNode* end)
{
ResetVisited();
std::stack<GraphNode*> nodeStack;
nodeStack.push(start);
//keep looping until the stack is empty.
//This will only happen once we've checked every node.
while (!nodeStack.empty())
{
//the rest of the algorithm goes in here
GraphNode* current = nodeStack.top();
nodeStack.pop();
if (!current->GetIsVisited())
{
current->SetIsVisited(true);
if (current == end)
{
return true;
}
for (int i = 0; i < int(current->GetEdgeList().size()); ++i)
{
nodeStack.push(current->GetEdgeList()[i]->GetEnd());
}
}
return false;
}
return false;
}
示例2: SearchBFS
bool Graph::SearchBFS(GraphNode* start, GraphNode* end)
{
ResetVisited();
std::queue<GraphNode*> nodeQueue;
nodeQueue.push(start);
//keep looping until the stack is empty.
//This will only happen once we've checked every node.
while (!nodeQueue.empty())
{
GraphNode* current = nodeQueue.front();
if (!current->GetIsVisited())
{
current->SetIsVisited(true);
if (current == end)
{
return true;
}
for (int i = 0; i < int(current->GetEdgeList().size()); ++i)
{
nodeQueue.push(current->GetEdgeList()[i]->GetEnd());
}
}
nodeQueue.pop();
return false;
}
return false;
}