BST comparing parents to the root

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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 = new char[strlen(root->name) + 1];
        strcpy(dest->name, root->name);
        
        copygreater(root->left, dest->left,holder);
        copygreater(root->right,dest->right,holder);
        
    }
    
}
What would the copy look like using your example tree for instance?
> 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?


1
2
        dest->name = new char[strlen(root->name) + 1];
        strcpy(dest->name, root->name);
http://www.cplusplus.com/reference/string/string/

1
2
    holder = strlen(root->name) + 1;
    if(int length = strlen(root->name) + 1 > holder)
see the value that you just assigned to `holder'
Topic archived. No new replies allowed.