本文整理汇总了C++中ExpressionNode::findParentOf方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionNode::findParentOf方法的具体用法?C++ ExpressionNode::findParentOf怎么用?C++ ExpressionNode::findParentOf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionNode
的用法示例。
在下文中一共展示了ExpressionNode::findParentOf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: simplify
ExpressionNode Addition::simplify(ExpressionNode& left, ExpressionNode& right)
{
std::clog << "checkpoint addsimplify" << std::endl;
//simplest case: at least one side is just 0
if (left.getType() == NUMBER && left.getValue().getInt() == 0)
{
return right;
}
else if (right.getType() == NUMBER && right.getValue().getInt() == 0)
{
return left;
}
// for each left term: for each right term: try adding
std::stack <ExpressionNode*> leftNodeStack;
ExpressionNode * currentLeftNode = &left;
bool leftFinished = false;
std::stack <ExpressionNode*> rightNodeStack;
ExpressionNode * currentRightNode = &right;
bool rightFinished = false;
ExpressionNode * tempNodePtr;
ExpressionNode newNode;
while (leftFinished == false)
{
std::clog << "looping left" << std::endl;
if (currentLeftNode->getType() == OPERATION && currentLeftNode->getOperation() == &ADDITION)
{
if (currentLeftNode->getFirstChild() == 0)
{
throw ExpressionNode::WrongArityError();
}
currentLeftNode = currentLeftNode->getFirstChild();
leftNodeStack.push(currentLeftNode);
continue;
}
// leaf term on left tree: traverse right tree
while (rightFinished == false)
{
std::clog << "looping right" << std::endl;
if (currentRightNode->getType() == OPERATION && currentRightNode->getOperation() == &ADDITION)
{
if (currentRightNode->getFirstChild() == 0)
{
throw ExpressionNode::WrongArityError();
}
currentRightNode = currentRightNode->getFirstChild();
rightNodeStack.push(currentRightNode);
continue;
}
std::clog << "checkpoint addsimplify: before isAddable; " << std::endl;
// leaf terms on both sides: attempt adding
if (isAddable(*currentLeftNode, *currentRightNode))
{
std::clog << "checkpoint addsimplify: after isAddable; " << std::endl;
std::clog << *currentLeftNode << " " << *currentRightNode << std::endl;
std::clog << "add testrun: " << addTerms(*currentLeftNode, *currentRightNode);
(*currentLeftNode).replace( addTerms(*currentLeftNode, *currentRightNode) );
std::clog << "checkpoint addsimplify: after addTerms; " << std::endl;
if (currentRightNode == &right)
{
//entire right tree has been assimilated
return left;
}
tempNodePtr = currentRightNode;
currentRightNode = right.findParentOf(*currentRightNode);
right.remove(*tempNodePtr);
}
while (true)
{
if (rightNodeStack.size() == 0)
{
rightFinished = true;
break;
}
currentRightNode = rightNodeStack.top();
rightNodeStack.pop();
if (currentRightNode->getRight() != 0)
{
currentRightNode = currentRightNode->getRight();
rightNodeStack.push(currentRightNode);
break;
}
}
}
while (true)
{
if (leftNodeStack.size() == 0)
{
leftFinished = true;
break;
}
currentLeftNode = leftNodeStack.top();
//.........这里部分代码省略.........