本文整理汇总了C++中ExpressionNode::getRight方法的典型用法代码示例。如果您正苦于以下问题:C++ ExpressionNode::getRight方法的具体用法?C++ ExpressionNode::getRight怎么用?C++ ExpressionNode::getRight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExpressionNode
的用法示例。
在下文中一共展示了ExpressionNode::getRight方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: simplify
ExpressionNode BinaryOperation::simplify(ExpressionNode& left)
{
if (left.getRight() > 0)
{
if ((left.getRight())->getRight() != 0)
{
throw ExpressionNode::WrongArityError("> 2 arguments for BinaryOperation");
}
return simplify(left, *left.getRight());
}
else
{
throw ExpressionNode::WrongArityError("only 1 argument for BinaryOperation");
}
}
示例2: operation
ExpressionNode::ExpressionNode(const ExpressionNode & other): //copy constructor
type(other.getType()), operation(other.getOperation()), activechildren(other.getOperation()->getArity()),
right(0), firstChild(0), variable(other.getVariable()), value(other.getValue())
{
setRight(other.getRight());
setFirstChild(other.getFirstChild()); // automatically also sets other children
}
示例3: findParentOf
ExpressionNode* ExpressionNode::findParentOf(const ExpressionNode& target)
{
ExpressionNode * currentNode = this;
std::stack <ExpressionNode*> nodeStack;
ExpressionNode * parent = 0;
while (true)
{
if (currentNode != 0)
{
if (currentNode == &target)
{
return parent;
}
nodeStack.push(currentNode);
parent = currentNode;
currentNode = currentNode->getFirstChild();
}
if (nodeStack.size() == 1) // only root left in stack
{
// target not found
throw TargetNotFoundError();
}
currentNode = nodeStack.top();
nodeStack.pop();
currentNode = currentNode->getRight();
}
}
示例4:
bool ExpressionNode::operator== (const ExpressionNode& other) const
{
ExpressionNode *selfptr;
ExpressionNode *otherptr;
if (getType() == other.getType() &&
getOperation() == other.getOperation() &&
getVariable() == other.getVariable() &&
getValue() == other.getValue() )
{
selfptr = firstChild;
otherptr = other.getFirstChild();
while (selfptr != 0 && otherptr != 0)
{
if (*selfptr == *otherptr)
{
selfptr = selfptr->getRight();
otherptr = otherptr->getRight();
}
else
{
return false;
}
}
if (selfptr == 0 && otherptr == 0)
{
return true;
}
else
{
assert(selfptr != otherptr);
return false;
}
}
else
{
return false;
}
}
示例5: simplify
ExpressionNode BinaryOperation::simplify(const ExpressionNode& root) const
{
ExpressionNode* left = root.getFirstChild();
if (left != 0)
{
if (left->getRight() != 0)
{
if ((left->getRight())->getRight() != 0)
{
throw ExpressionNode::WrongArityError("> 2 arguments for BinaryOperation");
}
return simplify( *left, *(left->getRight()) );
}
else
{
cerr << left << endl;
throw ExpressionNode::WrongArityError("only 1 argument for BinaryOperation");
}
}
else
{
throw ExpressionNode::WrongArityError("No arguments for BinaryOperation");
}
}
示例6: GenericError
std::ostream& operator<<(std::ostream& out, const ExpressionNode& node)
{
ExpressionNode * ptr = 0;
if (node.getType() == OPERATION)
{
if (node.getOperation() == 0)
{
if (node.getFirstChild() != 0)
{
throw ExpressionNode::GenericError("ERROR: inserting OPERATION parent node w/o operation into ostream");
}
else
{
out << "()";
return out;
}
}
if (node.getOperation()->isFuncFormat() == true)
{
out << *(node.getOperation()) << "(";
ptr = node.getFirstChild();
if (ptr != 0)
{
out << *ptr;
ptr = ptr->getRight();
while (ptr != 0)
{
out << ", " << *ptr;
ptr = ptr->getRight();
}
}
out << ")";
}
else
{
out << "(";
ptr = node.getFirstChild();
if (ptr != 0)
{
out << *ptr;
ptr = ptr->getRight();
while (ptr != 0)
{
out << *(node.getOperation()) << *ptr;
ptr = ptr->getRight();
}
}
out << ")";
}
}
else if (node.getType() == VARIABLE)
{
if (node.getVariable() == 0)
{
throw ExpressionNode::GenericError("ERROR: inserting VARIABLE node w/o variable into ostream");
}
out << *(node.getVariable());
}
else
{
if (node.getType() != NUMBER)
{
int i = node.getType();
std::clog << std::endl << i << std::endl;
}
assert(node.getType() == NUMBER);
out << node.getValue();
}
return out;
}
示例7: addTerms
ExpressionNode Addition::addTerms(const ExpressionNode& term1, const ExpressionNode& term2) const
{
clog << "checkpoint addTerms" << endl;
Number coefficient1;
Number coefficient2;
const ExpressionNode * varpart1;
const ExpressionNode * varpart2;
ExpressionNode * left;
ExpressionNode * right;
ExpressionNode newRight;
ExpressionNode newCoef;
ExpressionNode newNode;
if (term1.getType() == NUMBER)
{
coefficient1 = term1.getValue();
varpart1 = 0;
}
else if (term1.getType() == OPERATION)
{
if (term1.getOperation() == &MULTIPLICATION)
{
left = term1.getFirstChild();
right = left->getRight();
if (left->getType() == NUMBER)
{
coefficient1 = left->getValue();
varpart1 = right;
}
else if (right->getType() == NUMBER)
{
coefficient1 = right->getValue();
varpart1 = left;
}
else
{
coefficient1 = MULTIPLICATION.getIdentity();
varpart1 = &term1;
}
}
else
{
coefficient1 = MULTIPLICATION.getIdentity();
varpart1 = &term1;
}
}
else // VARIABLE
{
assert(term1.getType() == VARIABLE);
coefficient1 = MULTIPLICATION.getIdentity();
varpart1 = &term1;
}
if (term2.getType() == NUMBER)
{
coefficient2 = term2.getValue();
varpart2 = 0;
}
else if (term2.getType() == OPERATION)
{
if (term2.getOperation() == &MULTIPLICATION)
{
left = term2.getFirstChild();
right = left->getRight();
if (left->getType() == NUMBER)
{
coefficient2 = left->getValue();
varpart2 = right;
}
else if (right->getType() == NUMBER)
{
coefficient2 = right->getValue();
varpart2 = left;
}
else
{
coefficient2 = MULTIPLICATION.getIdentity();
varpart2 = &term2;
}
}
else
{
coefficient2 = MULTIPLICATION.getIdentity();
varpart2 = &term2;
}
}
else // VARIABLE
{
assert(term2.getType() == VARIABLE);
coefficient2 = MULTIPLICATION.getIdentity();
varpart2 = &term2;
}
if (varpart1 != 0 && varpart2 != 0)
{
if (*varpart1 == *varpart2)
{
clog << "addTerms simplify like terms" << endl
<< "coef1: " << coefficient1 << " var1: " << *varpart1 << endl
//.........这里部分代码省略.........