本文整理汇总了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);
}
}
}
示例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
//.........这里部分代码省略.........