本文整理汇总了C++中BSTNode::left方法的典型用法代码示例。如果您正苦于以下问题:C++ BSTNode::left方法的具体用法?C++ BSTNode::left怎么用?C++ BSTNode::left使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSTNode
的用法示例。
在下文中一共展示了BSTNode::left方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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
}
示例3: zigRLzigRL
void SplayTree::zigRLzigRL(BSTNode* aNode, BSTNode* aParent, BSTNode* aGrandParent){
BSTNode* ggParent = aGrandParent->parent();
SplayTree::Orientation orient = SplayTree::NONE;
if(ggParent !=NULL){
if(ggParent->left() == aGrandParent){
orient = SplayTree::LEFT;
}else{
orient = SplayTree::RIGHT;
}
}
zigRL(aParent, aGrandParent); //rotate right to left around grandparent first
zigRL(aNode, aParent);
if(orient ==SplayTree::LEFT){
ggParent->setLeft(aNode);
aNode->setParent(ggParent);
}else if(orient == SplayTree::RIGHT){
ggParent->setRight(aNode);
aNode->setParent(ggParent);
}
// debug_print();
}
示例4: zigLRzagRL
void SplayTree::zigLRzagRL(BSTNode* aNode, BSTNode* aParent, BSTNode* aGrandParent){
BSTNode* ggParent = aGrandParent->parent();
SplayTree::Orientation orient = SplayTree::NONE;
if(ggParent!=NULL){
if(ggParent->left() == aGrandParent){ //in the case of left subtree
orient = SplayTree::LEFT;
}else{
orient = SplayTree::RIGHT;
}
}
zigLR(aNode, aParent);
zigRL(aNode, aGrandParent);
if(orient ==SplayTree::LEFT){
ggParent->setLeft(aNode);
aNode->setParent(ggParent);
}else if(orient == SplayTree::RIGHT){
ggParent->setRight(aNode);
aNode->setParent(ggParent);
}
debug_print();
}
示例5: zagRLzigLR
void SplayTree::zagRLzigLR(BSTNode* aNode, BSTNode* aParent, BSTNode* aGrandParent){
// aNode is a right child of a left child
BSTNode* ggParent = aGrandParent->parent();
SplayTree::Orientation orient = SplayTree::NONE;
if(ggParent !=NULL){
if(ggParent->left() == aGrandParent){
orient = SplayTree::LEFT;
}else{
orient = SplayTree::RIGHT;
}
}
zigRL(aNode, aParent); //rotate from right to left around parent
zigLR(aNode, aGrandParent);
if(orient ==SplayTree::LEFT){
ggParent->setLeft(aNode);
aNode->setParent(ggParent);
}else if(orient == SplayTree::RIGHT){
ggParent->setRight(aNode);
aNode->setParent(ggParent);
}
// debug_print();
}