Lets say for example I have a BST that is sorted by char names, using strcmp. IF greater than 0 go right else go left.
I.E (this is just an example, they are not inserted correctly)
1 2 3 4 5
cat
/ \
dog buffalo
/ \ / \
fish mouse zebra snake
I wanted to make a copy of this BST IF the length of the nodes are greater than the root, how would I approach this? I kinda started on this but I'm not sure if I'm making this more difficult than it should be.
void BST::copygreater(node * root, node *& dest, int & holder)
{
if(!root)
{
dest = NULL;
return;
}
holder = strlen(root->name) + 1; //Don't know about this? If we do a recursive call then the value would change every call?
if(int length = strlen(root->name) + 1 > holder)
{
dest = new node;
dest->name = newchar[strlen(root->name) + 1];
strcpy(dest->name, root->name);
copygreater(root->left, dest->left,holder);
copygreater(root->right,dest->right,holder);
}
}
> I.E (this is just an example, they are not inserted correctly)
e.g., exempli gratia, for example.
i.e., id est, in other words.
I.E, internet explorer
given that the example does not shown an bst, ¿what is its purpose?