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


C++ TNode::getParent方法代码示例

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


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

示例1: if

void bsTree<T>::remove(const T & item)
{	
		TNode<T> *tN = search(root, item);					//Returns node of value, item.
		if(!tN) 											//if node is not found, remove nothing.
			return;	

		TNode<T> *pN= tN->getParent();						//Points to tN's parent.
		
		if(tN->getLeft() == NULL && tN->getRight() == NULL) //node is leaf
		{
			removeLink(tN, pN, NULL);
		}
		else if(tN->hasOnlyLeft())						    //Node has only left child
		{
			removeLink(tN, pN, tN->getLeft());
		}
		else if(tN->hasOnlyRight())						    //Node has only right child
		{
			removeLink(tN, pN, tN->getRight());
		}
		else 											    // has two children
		{
			if(tN->getValue() > root->getValue())
			{
				getSmallest(tN->getRight(), tN, tN);
			}
			else
			{
				getBiggest(tN->getLeft(), tN, tN);
			}
		}
}
开发者ID:austinhofmann,项目名称:School,代码行数:32,代码来源:bsTree.cpp

示例2: converseAST

std::shared_ptr<GNode> NextExtractor::converseAST(shared_ptr<CFG> cfg,TNode* curTNode, shared_ptr<GNode> curGNodeParent, shared_ptr<stack<shared_ptr<GNode>>> level)
{
	if (curTNode == NULL){
		return curGNodeParent;
	}
	string nodeType = curTNode->getNodeType();
	
		//ignore procedure and stmtlst TNode
	if (nodeType == "STMTLST_NODE") {
		return converseAST(cfg,  curTNode->getChild(0),curGNodeParent,level);
							   }						   
	else if(nodeType=="PROC_NODE") {
		return converseAST(cfg, curTNode->getChild(0),curGNodeParent,level);
								 }
	else if(nodeType=="THEN_NODE"){
		return converseAST(cfg ,curTNode->getChild(0), curGNodeParent, level);
						   }
	else if(nodeType=="ELSE_NODE"){
		return converseAST(cfg ,curTNode->getChild(0), curGNodeParent, level);
						   }
	else if(nodeType=="ASSIGN_NODE"){
		shared_ptr<GNode> gNode = setlink(cfg, curTNode, curGNodeParent, level);
		return converseAST(cfg ,  curTNode->getRightSibling(), gNode, level);

							 }
	else if(nodeType=="CALL_NODE"){
		shared_ptr<GNode> gNode = setlink(cfg, curTNode, curGNodeParent, level);
		return converseAST(cfg , curTNode->getRightSibling(), gNode, level);
						   }

	else if(nodeType=="IF_NODE"){
		shared_ptr<GNode> gNode = setlink(cfg, curTNode, curGNodeParent, level);
		level->push(gNode);
		converseAST(cfg ,  curTNode->getChild(0), gNode, level); // converse then node
		gNode = converseAST(cfg, curTNode->getChild(0)->getRightSibling(), gNode, level); // converse else node
		nodeMap.insert(pair<int, shared_ptr<GNode>>(gNode->getStmtNum(), gNode));

		if(lastIfWhileStmtStack.size() > 0 && lastIfWhileStmtStack.top().second == curTNode){

			TNode* curTNodeParent =  curTNode->getParent();
			string curTNodeType = curTNode->getNodeType();

			//this is for while-if code
			if(curTNodeParent->getNodeType() == "STMTLST_NODE" && curTNodeParent->getParent()->getNodeType().compare("WHILE_NODE") == 0)
			{
				cfg->setNext(gNode, level->top());
				level->pop();
			}

			//this is for if-if-LEFT code
			else if(curTNodeParent->getNodeType() == "STMTLST_NODE" && curTNodeParent->getParent()->getData().compare("then") == 0)
			{
				cout << "test" << endl;
				shared_ptr<GNode> nextG = make_shared<GNode>(INT_MIN, "EMPTY");
				lastIfNode.insert(pair<int,shared_ptr<GNode>>(level->top()->getStmtNum(), nextG));
				firstIfNode.insert(pair<shared_ptr<GNode> ,int>(nextG , level->top()->getStmtNum()));
				cfg->setNext(gNode,nextG);
				level->pop();
				level->push(nextG);
			}

			//this is for if-if-RIGHT code
			else if(curTNodeParent->getNodeType() =="STMTLST_NODE" && curTNodeParent->getParent()->getData().compare("else") == 0)
			{
				shared_ptr<GNode> nextG = level->top();
				cfg->setNext(gNode,level->top());
				level->pop();
				lastIfWhileStmtStack.pop();
				return nextG;
			}

			
			lastIfWhileStmtStack.pop();
			return gNode;
		}
		else
		{
			return converseAST(cfg,curTNode->getRightSibling(),gNode,level);//recursive !! curG is the empty node
		}
						 }

	else if(nodeType=="WHILE_NODE")
		{
			shared_ptr<GNode> gNode = setlink(cfg, curTNode, curGNodeParent, level);
			level->push(gNode);
			converseAST(cfg, curTNode->getChild(0), gNode, level); //converse while node

			if(lastIfWhileStmtStack.size() > 0 && lastIfWhileStmtStack.top().second == curTNode){

				TNode* curTNodeParent = curTNode->getParent();
				string curTNodeType = curTNode->getNodeType();

				//this is for while-while
				if(curTNodeParent->getNodeType() == "STMTLST_NODE" && curTNodeParent->getParent()->getNodeType().compare("WHILE_NODE") == 0) 
				{
					cfg->setNext(gNode, level->top());
					level->pop();
				}

				//this is for if-while-LEFT code
//.........这里部分代码省略.........
开发者ID:khzaw,项目名称:xcalibur,代码行数:101,代码来源:NextExtractor.cpp


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