Rooted Tree (Family tree)

This is a discussion on Rooted Tree (Family tree) within the C Programming forums, part of the General Programming Boards category; Here is the problem: there are members of a family that should be insert into tree but there are also ...

  1. #1
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142

    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,185
    What's the question, exactly? Do you want to update newnode->spounce->children whenever you update newnode->children, or what?

  3. #3
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142
    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 05:16 PM.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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
    ch4
    ch4 is offline
    Newbeer ch4's Avatar
    Join Date
    Jan 2007
    Posts
    142
    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, 06: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, 04: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, 11:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21