Exemplo n.º 1
0
 /** Return the leftmost node of the subtree.
  *  PRECONDITION: this BSTNode is a node in a BST.
  *  POSTCONDITION: the BST is unchanged.
  *  RETURNS: The BSTNode that is the leftmost node of the subtree.
  */
 BSTNode<Data>* leftmostNode() {
     /* if this has a left child, recurse on that. Otherwise, return this. */
     if (left!=NULL) {
         return left->leftmostNode();
     } else {
         return this;
     }
 }
Exemplo n.º 2
0
 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();
     }
 }