last day (15 days later) » 

11:34 AM
1
A: How to grow that Quadtree at each node

BromanA recursive approach seems right. Something like this: void growTree(Node * root) { for(int i=0; i<4; i++) { if(root->child[i] == NULL) root->child[i] = makeNode(0,0,root->level+1); else growTree(root->child[i]); } } I would also suggest redesigning makeNode. Something ...

 
Would that work even if the head node already has a child?
 
I assumed that the tree would have 0 or 4 children. Is that wrong?
@anon2000 What do you want to happen if a node has 1,2 or 3 children?
 
I wanted the code to traverse each node and grow it. So a full level 2 tree would become a full level 3 tree or a non-uniform level 2 tree would become a non-uniform level 3 tree.
If the node had had 1,2 or 3 children then the children would grow by one level
 
@anon2000 Fixed it (again)
 
I get a segmentation fault for some reason. You wouldn't happen to know why would you?
 
11:34 AM
@anon2000 Yes, I'm working on it. But clarify one thing. Do you want four new nodes at every NULL node?
 
No, just the one
 
@anon2000 Fixed
 
Thank you. But I'm not sure why I'm not seeing any change when I view the quadtree in gnuplot
 
@anon2000 I have no explanation to that. I tested it with the code void printTree(Node * root) { if(root) printf("Node: %f %f %d\n", root->xy[0], root->xy[1], root->level); for(int i=0; i<4; i++) { if(root->child[i] != NULL) { printTree(root->child[i]); } } } and it seems to work.
 
Okay no worries. Thanks
Would I call growTree by doing growTree(head)?
Hey,
I was wondering if you help me figure out why this was going wrong for me.

I wouldn't mind emailing you all the code and I'd be willing to pay you for it.
 
 
1 hour later…
12:38 PM
?
 
 
3 hours later…
3:57 PM
void growTree(Node * p) {
for(int i=0; i<4; i++) {
if(p->child[i] == NULL) {
p->child[i] = makeNode(0,0,p->level+1);
}
else
growTree(p->child[i]);
}
}
That is for adding one node to the node thats are NULL but what if I want to add 4 nodes?
I know that you asked me to clarify this earlier but I keep getting a segmentation fault and I was wondering if that might fix it/
Thanks
 

last day (15 days later) »