1 Replies - 240 Views - Last Post: 23 January 2013 - 10:45 PM Rate Topic: -----

#1 asdk77  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 16-November 12

How to copy a tree in C

Posted 23 January 2013 - 09:53 PM

I want to copy a part of a tree.
struct node
{
...
int num_number; //number of children nodes
node **children; //pointer point to children nodes. When I copy the node, how can I deal with **children? Right now, there is no children yet.
}
void copy_tree(node *node, node *T)
{
    int i;
    char number[12] = {0}; //used in case of if
    int n = node->num_children; 
    if (node == NULL)
        T = NULL;
    if(...)
    {
        .... // copy the node
    }
    else
    {
                ....  // copy the node
    }
    for(i=0; i<n; i++)
        copy_tree(node->children[i], T->children[i]); // I want to copy the children nodes recursively, but the new node has no children; that is T->children not existing, how can I copy the children nodes and allocate to parent? 


I hope someone can give some tips.
Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: How to copy a tree in C

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4354
  • View blog
  • Posts: 12,160
  • Joined: 18-April 07

Re: How to copy a tree in C

Posted 23 January 2013 - 10:45 PM

Go check out the answer I posted on codecall... you know, that other place you are obviously plastering your question to.

Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1