本文整理汇总了C++中BSTNode::ancestralSuccessor方法的典型用法代码示例。如果您正苦于以下问题:C++ BSTNode::ancestralSuccessor方法的具体用法?C++ BSTNode::ancestralSuccessor怎么用?C++ BSTNode::ancestralSuccessor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BSTNode
的用法示例。
在下文中一共展示了BSTNode::ancestralSuccessor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ancestralSuccessor
/** Return the inorder ancestral successor of this BSTNode in a BST, or
* 0 if none.
* PRECONDITION:this BSTNode is a node in a BST.
* POSTCONDITION: the BST is unchanged.
* RETURNS: the BSTNode that is the inorder ancestral successor of this
* BSTNode, or 0 if there is none.
*/
BSTNode<Data>* ancestralSuccessor() {
/* Find and return a successor that is an ancestor, if it exists. */
if (parent==NULL) {
return NULL;
} else if (this==parent->right) {
return parent->ancestralSuccessor();
} else {
return parent;
}
}
示例2: successor
BSTNode<Data>* successor() {
/* Determine if the right child or parent is successor. If neither, and
parent exists, find out if one of the parents ancestors is the successor.
If no successor exists, return 0. */
if (right!=NULL) {
return right->leftmostNode();
} else if (parent==NULL) {
return NULL;
} else if (this==parent->left) {
return parent;
} else {
return parent->ancestralSuccessor();
}
}