本文整理汇总了C++中BSTNode::parent方法的典型用法代码示例。如果您正苦于以下问题:C++ BSTNode::parent方法的具体用法?C++ BSTNode::parent怎么用?C++ BSTNode::parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSTNode
的用法示例。
在下文中一共展示了BSTNode::parent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: splay
void SplayTree::splay(BSTNode* aNode){
if(aNode ==NULL || aNode->parent() ==NULL){ //two special cases
return;
}
BSTNode* parent = aNode->parent();
BSTNode* grandParent = parent->parent();
cout<<"splaying the node: "<<aNode->key()<<endl;
while(parent != NULL && grandParent != NULL){
//all zigzig zigzag
zigzigzigzag(aNode);
parent = aNode->parent(); //updating parent and grandparent
if(parent ==NULL){
break; //effectively end the function
}
grandParent = parent->parent();
if(grandParent == NULL){
break;
}
}
if(grandParent == NULL && parent != NULL){ //parent is the root
if(parent->left() ==aNode){
zigLR(aNode, parent);
}else{
zigRL(aNode, parent);
}
}
debug_print(); //finly, dump the tree structe in Graphviz format
}
示例2: zigzigzigzag
void SplayTree::zigzigzigzag(BSTNode* aNode){
BSTNode* parent = aNode->parent();
BSTNode* grandParent = parent->parent();
if(parent ==NULL || grandParent==NULL){
return;
}
if(grandParent->right() == parent && parent->left() ==aNode){
cout<<"performing zigLRzagRL "<<endl;
zigLRzagRL( aNode, parent, grandParent);
return;
}
else if(grandParent->left() == parent && parent->right() ==aNode){
cout<<"performing zagRLzigLR "<<endl;
zagRLzigLR ( aNode, parent, grandParent);
return;
}
else if(grandParent->left() == parent && parent->left() ==aNode){
cout<<"performing zigLRzigLR "<<endl;
zigLRzigLR( aNode, parent, grandParent);
return;
}
else if(grandParent->right() == parent && parent->right() ==aNode){
cout<<"performing zigRLzigRL "<<endl;
zigRLzigRL ( aNode, parent, grandParent);
return;
}
else
cout<<"sum sing wong: "<<aNode->key()<<"'s parent: "<<parent->key()<<" grandparent: "<<grandParent->key()<<endl;
return;
}
示例3: cut
//delete the entry
void SplayTree::cut(string aKey){
cout<<"<<<------internal transcript----->>>"<<endl;
BSTNode* node = BST::find(aKey); //the node contains the exact key
if((node->key()!= aKey) || node ==NULL ){
splay(node); //splay it anyway [2]
cout<<"\nsorry, the musician: "<<aKey<<" is not in the list"<<endl;
return;
}
if(node->parent() != NULL && (node->key() ==aKey)){
cout<<"node: "<<node->key()<<" has parent"<<endl;
node = node->parent(); //node now pting to its parent
cout<<"node now pting to its parent: "<<node->key()<<endl;
BST::remove(aKey); //remove the key
splay(node); //splay the parent to the root [2]
}else if (node->parent() ==NULL){ //in the case node is the root
BST::remove(aKey);
}
cout<<"delete sucessful!"<<endl;
}