my node structure is
The aim is to create an array of generic pointers that point to the data on each node of the tree. The pointers must be in order, meaning from smallest to largest.Code:typedef struct node_ { void * key; void * data; struct node_ * left; struct node_ * right; }node, *pnode;
My idea is to do an in-order traversal
my concern with the above is that after returning (cur->data) the program won't check for the right child. If that is the case, how can i solve it?Code:void * point_data(node *cur) { if (cur->left) point_data(cur->left); return (cur->data); if (cur->right) point_data(cur->right); }
also, as mentioned above, i want to create an array of said pointers. How can i do that?
my first reaction was
where root is of type node *. With the above i believe i would just get all pointers pointing to the same first element. I'm at a mental block right now :S any help is greatly appreciated.Code:void * p[telem]; int i; for(i=0; i < (telem-1);i++) p[i] = point_data(root);



LinkBack URL
About LinkBacks


