Thread: Family Tree

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    35

    Question Family Tree

    Hi all!
    I'm writing a "family tree"program. there's a function in my class Node which is named SON. it gets 2 strings as arguments (they represent the name of the son and the father to be related respectively). I've got a problem here. if you look at the code below:
    Code:
    class Node
    {
        Node *father;
        Node *son;
        string name;
        vector<Node *> kid;
    
    
    void ADD(string s)
    	{
    		Node *n= new Node;
    		n->name=s;
    		nom.push_back(n);
    	}
    
    void SON(string s, string f)
    	{
    		for(int i=0 ; i<nom.size() ; i++)
    			{
    				if(nom[i]->name==f)
    					father=nom[i];
    				if (nom[i]->name==s)
    					son=nom[i];
    			}
    		father->kid.push_back(son);
    		son->father=father;
    
    
    	}
    };
    Does it make sense to do so? doesn't function SON, mix up the father and son with the one in the outer scope?
    Last edited by Farnaz; 03-07-2011 at 01:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Tree Search
    By C++Newbie in forum C++ Programming
    Replies: 7
    Last Post: 04-05-2011, 01:17 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 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