C-Programmierung

Kd-Tree Deletion

kd-Tree Median Insertion | | Nearest Neighbor

When the life time of a kd-tree ends, all inserted nodes have to be deleted.
This means, we need to remove all nodes recursively in the destructor.

We do so by traversing the entire tree recursively starting at the root node:

for a particular node to be removed

  • remove the left subtree of the node
  • remove the right subtree of the node
  • then delete the actual node
KDTree::remove(Node *node)
{
   if (node)
   {
      remove(node->leftSpace);
      remove(node->rightSpace);

      delete node;
   }
}

KDTree::~KDTree()
{
   remove(root);
}


kd-Tree Median Insertion | | Nearest Neighbor

Options: