src/classify/kdtree.cpp
void KDDelete(KDTREE *Tree, float Key[], void *Data) {
  int Level;
  KDNODE *Current;
  KDNODE *Father;

  /* initialize search at root of tree */
  Father = &(Tree->Root);
  Current = Father->Left;
  Level = NextLevel(Tree, -1);

  /* search tree for node to be deleted */
  while ((Current != nullptr) && (!NodeFound(Current, Key, Data))) {
    Father = Current;
    if (Key[Level] < Current->BranchPoint) {
      Current = Current->Left;
    } else {
      Current = Current->Right;
    }

    Level = NextLevel(Tree, Level);
  }

  if (Current != nullptr) { /* if node to be deleted was found */
    if (Current == Father->Left) {
      Father->Left = nullptr;
      Father->LeftBranch = Tree->KeyDesc[Level].Min;
    } else {
      Father->Right = nullptr;
      Father->RightBranch = Tree->KeyDesc[Level].Max;
    }

    InsertNodes(Tree, Current->Left);
    InsertNodes(Tree, Current->Right);
    delete Current;
  }
}
/**
 * This routine deletes a node from Tree.  The node to be
 * deleted is specified by the Key for the node and the Data
 * contents of the node.  These two pointers must be identical
 * to the pointers that were used for the node when it was
 * originally stored in the tree.  A node will be deleted from
 * the tree only if its key and data pointers are identical
 * to Key and Data respectively.  The tree is re-formed by removing
 * the affected subtree and inserting all elements but the root.
 *
 * @param Tree K-D tree to delete node from
 * @param Key key of node to be deleted
 * @param Data data contents of node to be deleted
 */
This routine deletes a node from Tree.  The node to be
deleted is specified by the Key for the node and the Data
contents of the node.  These two pointers must be identical
to the pointers that were used for the node when it was
originally stored in the tree.  A node will be deleted from
the tree only if its key and data pointers are identical
to Key and Data respectively.  The tree is re-formed by removing
the affected subtree and inserting all elements but the root.

@param Tree K-D tree to delete node from
@param Key key of node to be deleted
@param Data data contents of node to be deleted
This routine deletes a node from Tree . The node to be deleted is specified by the Key for the node and the Data contents of the node . These two pointers must be identical to the pointers that were used for the node when it was originally stored in the tree . A node will be deleted from the tree only if its key and data pointers are identical to Key and Data respectively . The tree is re - formed by removing the affected subtree and inserting all elements but the root . @param Tree K - D tree to delete node from @param Key key of node to be deleted @param Data data contents of node to be deleted
void KDDelete(KDTREE *Tree, float Key[], void *Data) {
  int Level;
  KDNODE *Current;
  KDNODE *Father;
  Father = &(Tree->Root);
  Current = Father->Left;
  Level = NextLevel(Tree, -1);
  while ((Current != nullptr) && (!NodeFound(Current, Key, Data))) {
    Father = Current;
    if (Key[Level] < Current->BranchPoint) {
      Current = Current->Left;
    } else {
      Current = Current->Right;
    }
    Level = NextLevel(Tree, Level);
  }
  if (Current != nullptr) { 
    if (Current == Father->Left) {
      Father->Left = nullptr;
      Father->LeftBranch = Tree->KeyDesc[Level].Min;
    } else {
      Father->Right = nullptr;
      Father->RightBranch = Tree->KeyDesc[Level].Max;
    }
    InsertNodes(Tree, Current->Left);
    InsertNodes(Tree, Current->Right);
    delete Current;
  }
}
void KDDelete ( KDTREE * Tree , float Key [ ] , void * Data ) { int Level ; KDNODE * Current ; KDNODE * Father ; Father = & ( Tree -> Root ) ; Current = Father -> Left ; Level = NextLevel ( Tree , -1 ) ; while ( ( Current != nullptr ) && ( ! NodeFound ( Current , Key , Data ) ) ) { Father = Current ; if ( Key [ Level ] < Current -> BranchPoint ) { Current = Current -> Left ; } else { Current = Current -> Right ; } Level = NextLevel ( Tree , Level ) ; } if ( Current != nullptr ) { if ( Current == Father -> Left ) { Father -> Left = nullptr ; Father -> LeftBranch = Tree -> KeyDesc [ Level ] . Min ; } else { Father -> Right = nullptr ; Father -> RightBranch = Tree -> KeyDesc [ Level ] . Max ; } InsertNodes ( Tree , Current -> Left ) ; InsertNodes ( Tree , Current -> Right ) ; delete Current ; } }
This routine deletes a node from Tree.
This routine deletes a node from Tree .
/* initialize search at root of tree */ /* search tree for node to be deleted */ /* if node to be deleted was found */