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


C++ BSTNode::parent方法代码示例

本文整理汇总了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
}
开发者ID:yxuan,项目名称:Song-Playlist-Manager,代码行数:30,代码来源:splay.cpp

示例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;

} 
开发者ID:yxuan,项目名称:Song-Playlist-Manager,代码行数:31,代码来源:splay.cpp

示例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;
}
开发者ID:yxuan,项目名称:Song-Playlist-Manager,代码行数:20,代码来源:splay.cpp


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