本文整理汇总了C++中std::list::isOpen方法的典型用法代码示例。如果您正苦于以下问题:C++ list::isOpen方法的具体用法?C++ list::isOpen怎么用?C++ list::isOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::list
的用法示例。
在下文中一共展示了list::isOpen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
//Alt. version of preservePath()
void Graph::preservePath2(std::list< std::list<Node>::iterator >& pidPath, std::list<Node>::iterator pendNode)
{
std::list< std::list<Node>::iterator >::iterator pathIter = pidPath.begin();
while (*pathIter != pendNode)
{
std::list<Node>::iterator pn = *pathIter;
if (pn->isOpen())
pn->setNodeType(Node::OPEN);
else pn->setNodeType(Node::CLOSED);
pathIter++;
}
if (pendNode->isOpen())
pendNode->setNodeType(Node::OPEN);
else pendNode->setNodeType(Node::CLOSED);
}
示例2: preservePath
//Set nodes in path to OPEN
void Graph::preservePath(std::list<Node>::iterator pbaseNode, std::list<Node>::iterator ptargetNode)
{
//make sure iterators are valid
std::list<Node>::iterator pnull = std::list<Node>::iterator(NULL);
if (pbaseNode == pnull || ptargetNode == pnull)
{
//std::cout << "\nNULL ITERATORS PASSED TO preservePath()\n";
return;
}
std::vector<short> baseWord = pbaseNode->getElemName();
std::vector<short> targetWord = ptargetNode->getElemName();
//target word must be longer than or equal length as base word
if (targetWord.size() < baseWord.size())
{
//std::cout << "\nPRESERVE PATH BAD RETURN1\n";
return;
}
//should never touch the identity; this is a special case which is handled in initial step
if (baseWord[0] == 0 || targetWord[0] == 0)
{
//std::cout << "\nPRESERVE PATH BAD RETURN2\n";
return;
}
//if words are identical there's nothing to do
if (baseWord == targetWord)
{
//std::cout << "\nPRESERVE PATH BAD RETURN3\n";
return;
}
//return;
//At this point we know the nodes exist, their words have appropriate sizes, they're not the identity,
//and they're not equal. But we could still have the problem that the base word is not contained
//in the leftmost portion of the target word, so we check for that.
bool baseContained = true;
int i;
for (i = 0; i < baseWord.size() - 1; i++) //up until the last letter, each exponent identical
if (baseWord[i] != targetWord[i])
baseContained = false;
if (baseWord[i] > targetWord[i]) //on the last letter, the exponent in base may be less or equal
baseContained = false;
if (baseContained == false)
{
std::cout << "\nPRESERVE PATH not contained:\n";
pbaseNode->printWord();
std::cout << "\n";
ptargetNode->printWord();
std::cout << "\n";
return;
}
//nodes have been checked
std::list<Node>::iterator psetNode = ptargetNode;
while (targetWord.size() != baseWord.size()) //stop at last exponent of baseWord
{
int i = targetWord.size() - 1; //always index of last exponent in targetWord
int exp = targetWord[i]; //last exponent on targetWord
while (exp > 0)
{
targetWord[i] = exp;
psetNode = searchNodes(&targetWord);
if (psetNode == std::list<Node>::iterator(NULL))
{
std::cout << "\nAttempt to set node via null iterator in preservePath()\n";
return;
}
if (psetNode->getNodeType() != Node::TEMP && psetNode != ptargetNode)
{
//it's okay to hit a preserved node, this means the nodes before this one will also
//be preserved
return;
}
psetNode->setNodeType(Node::OPEN);
exp--;
}
targetWord.pop_back(); //remove exponent just cleared
}
int d = targetWord.size() - 1;
if (targetWord[d] == baseWord[d])
{
if(pbaseNode->isOpen())
psetNode->setNodeType(Node::OPEN);
else psetNode->setNodeType(Node::CLOSED);
return;
}
int exp = targetWord[d]; //last exponent on targetWord
while (exp > baseWord[d])
{
targetWord[d] = exp;
psetNode = searchNodes(&targetWord);
if (psetNode == std::list<Node>::iterator(NULL))
{
std::cout << "\nAttempt to set node via null iterator in preservePath()\n";
return;
}
//.........这里部分代码省略.........