当前位置: 首页>>代码示例>>C++>>正文


C++ BTreeNode::type方法代码示例

本文整理汇总了C++中BTreeNode::type方法的典型用法代码示例。如果您正苦于以下问题:C++ BTreeNode::type方法的具体用法?C++ BTreeNode::type怎么用?C++ BTreeNode::type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BTreeNode的用法示例。


在下文中一共展示了BTreeNode::type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processConstant

QString Expression::processConstant( const QString & expr, bool * isConstant )
{
	bool temp;
	if (!isConstant)
		isConstant = &temp;
	
	QString code;
	
	// Make a tree to put the expression in.
	BTreeBase *tree = new BTreeBase();
	BTreeNode *root = new BTreeNode();

	// parse the expression into the tree
	buildTree(expr,tree,root,0);
	// compile the tree into assembly code
	tree->setRoot(root);
	tree->pruneTree(tree->root());
	//code = traverseTree(tree->root());
	// Look to see if it is a number
	if( root->type() == number )
	{
		code = root->value();
		*isConstant = true;
	}
	else
	{
		code = "";
		*isConstant = false;
	}
	
	// Note deleting the tree deletes all nodes, so the root
	// doesn't need deleting separately.
	delete tree;
	return code;
}
开发者ID:ktechlab,项目名称:ktechlab,代码行数:35,代码来源:expression.cpp

示例2: pruneTree

void BTreeBase::pruneTree(BTreeNode *root, bool /*conditionalRoot*/)
{
	Traverser t(root);
	
	t.descendLeftwardToTerminal();
	bool done = false;
	while(!done)
	{
	//t.descendLeftwardToTerminal();
	if( t.current()->parent() )
	{
		if( t.oppositeNode()->hasChildren() ) pruneTree(t.oppositeNode());
	}
	
	t.moveToParent();
	if( !t.current()->hasChildren() )
	{
		//if(t.current() == t.root()) done = true;
		if(!t.current()->parent()) done = true;
		continue;
	}

	BTreeNode *l = t.current()->left();
	BTreeNode *r = t.current()->right();
	BTreeNode *n = 0;
	BTreeNode *z = 0;
	

	// Deal with situations where there are two constants so we want
	// to evaluate at compile time
	if( (l->type() == number && r->type() == number) ) // && !(t.current()==root&&conditionalRoot) )
	{
		if(t.current()->childOp() == Expression::division && r->value() == "0" ) 
		{
			t.current()->setChildOp(Expression::divbyzero);
			return;
		}
		QString value = QString::number(Parser::doArithmetic(l->value().toInt(),r->value().toInt(),t.current()->childOp()));
		t.current()->deleteChildren();
		t.current()->setChildOp(Expression::noop);
		t.current()->setType(number);
		t.current()->setValue(value);
	}
	
	// Addition and subtraction
	else if(t.current()->childOp() == Expression::addition || t.current()->childOp() == Expression::subtraction)
	{
	// See if one of the nodes is 0, and set n to the node that actually has data,
	// z to the one containing zero.
	bool zero = false;
	if( l->value() == "0" )
	{
		zero = true;
		n = r;
		z = l;
	}
	else if( r->value() == "0" )
	{
		zero = true;
		n = l;
		z = r;
	}
	// Now get rid of the useless nodes
	if(zero)
	{
		BTreeNode *p = t.current(); // save in order to delete after

		replaceNode(p,n);
		t.setCurrent(n);
		// Delete the old nodes
		delete p;
		delete z;
	}
	}
	
	// Multiplication and division
	else if(t.current()->childOp() == Expression::multiplication || t.current()->childOp() == Expression::division)
	{
	// See if one of the nodes is 0, and set n to the node that actually has data,
	// z to the one containing zero.
	bool zero = false;
	bool one = false;
	if( l->value() == "1" )
	{
		one = true;
		n = r;
		z = l;
	}
	else if( r->value() == "1" )
	{
		one = true;
		n = l;
		z = r;
	}
	if( l->value() == "0" )
	{
		zero = true;
		n = r;
		z = l;
	}
//.........这里部分代码省略.........
开发者ID:ktechlab,项目名称:ktechlab-0.3,代码行数:101,代码来源:btreebase.cpp


注:本文中的BTreeNode::type方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。