when adding data into a binary tree, is it possible to add more than one field of data per node? for example say the first left child will have something like "info",
would you be able to add a name and age field, then be able to display it? it may be hard to understand what im trying to say.
here is what i have so far,

void add(node* & x, string information)
{
    if( x== NULL ) 
    {
       
        x= new node(information);    
    }
    else if( information> x->data )     {
        add( x->right, information);     
    }
    else  
    {
        add( x->left, information);      
    }
}

with this, im able to add a single string to either the left or right child depending on the scenario. what i want to do, is add, say a string for the name, one for the age and so on. how would i be able to do that?

struct Info{
 string name;
 int age;
 Info(const string& name = "", int age = 0)
  : name(name), age(age){}
};
void add(node* & x, const Info& information)
{
    if( x== NULL ) 
    {
       
        x= new node(information);    
    }
    else if( information> x->data )     {
        add( x->right, information);     
    }
    else  
    {
        add( x->left, information);      
    }
}

//...
//...
myList.add( new Info("james",23) );
myList.add( new Info("charles",32 ) );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.