I'm having trouble with my deleteNode function... I need the program to be able to delete only one node when you right click on it, but not the rest of the nodes in the quadtree.
Here's the current deleteNode function... let me know if you see the problem or the logic that I am missing!
Code:
void deleteNode(qnode *root, int mousex, int mousey)
{
int i, dist;
if ( root == NULL ) return; // Sub-tree is empty. This situation will generally not occur
dist = sqrt(pow((mousex - root->px),2) + pow((mousey - root->py),2));
printf("distance = %d\n", dist);
if (dist<5)
{
printf("delete this point\n");
deleteNode(root->children[i], mousex, mousey);
free(root->children[i]);
root->children[i] = NULL;
return;
}
else {
for (i=0; i<4; i++)
{
if ( root->children[i] != NULL )
{
deleteNode(root->children[i], mousex, mousey);
}
}
}
}