Thread: Rooted Tree (Family tree)

  1. #1
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154

    Rooted Tree (Family tree)

    Here is the problem: there are members of a family that should be insert into tree but there are also their spounces that should insert into tree as separated nodes. The only common between original member and their spounces is that spounces must have the same children num, array with children ids, generation, children pointer which is the problem.

    Member struct
    Code:
    typedef struct _Node
    {
     int ID;
     char *Name;
     int ParentID;
     int Date_of_birth;
     char *Place_of_birth;
     int SpounceID;
     int k;
     int *ChildrenID;
     
     int Generation;
     struct Node *next_family;
     struct Node *parent;
     struct Node *spounce;
     struct Node *children;
    }Node;
    If children pointer changes for a member i want to change and for the member's spounce.
    I think the problem located in assignment in the beginning.


    Here is where pointers assignment takes place, the rest assignment is ok, here is the problem. temp is the member of tree and newnode his/her spounce.
    Code:
           //If exists and able to accept spounce
           if((temp!=NULL)&&(temp->SpounceID!=-1))
           {
            //Assign last values
            temp->spounce=newnode;
            newnode->spounce=temp;
            newnode->ChildrenID=temp->ChildrenID;
            newnode->children=temp->children;           // <------Here
            newnode->Generation=temp->Generation;
           }


    Thanks in advance.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    What's the question, exactly? Do you want to update newnode->spounce->children whenever you update newnode->children, or what?

  3. #3
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154
    Exactly,
    I want a pointer that belongs both newnode and temp.
    If i update it for newnode i want it updated and for temp and reverse. Something like "common" pointer

    To make it easier
    2 nodes as the above

    A_node B_node

    data_A != data_B //I don't care

    *children_A == *children_B

    If i change A's children then B's children should change because they supposed to be father/mother, grandpa/grandma etc.
    Last edited by ch4; 10-14-2008 at 04:16 PM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Then you'll have to do so. Every time you change children, change spouse->children with it. (In other words, this is your job, not the compiler's.)

  5. #5
    Registered User ch4's Avatar
    Join Date
    Jan 2007
    Posts
    154
    Quote Originally Posted by tabstop View Post
    Then you'll have to do so. Every time you change children, change spouse->children with it. (In other words, this is your job, not the compiler's.)
    I've used that in some functions but there still many that i can do it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  2. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 09:09 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM