Click here to Skip to main content
15,906,569 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have binary tree in java to build family members tree.

In add function, I want to determine the parent that will have new child, after that, the user enter the name of new child.

The problem I face is the family tree cannot compare such as the tree has integer numbers.

Is there a method to do this?

This is a main in my code
Java
static public void main(String args[])
  {
      System.out.println(">>> creating empty tree");
      StringBinaryTree t = new StringBinaryTree();
      System.out.println(">>> adding elements to the tree");
      t.add("lion","");
      t.add("shark","r");
      t.add("elephant","l");
      t.add("zebra","rr");
  }

Thanks for the help
Posted
Updated 25-May-11 21:43pm
v6
Comments
Sergey Alexandrovich Kryukov 26-May-11 3:28am    
Not clear. What do you want to achieve?
--SA
dedoooo 26-May-11 3:35am    
I want to achieve read the input from the user for the new child .e.g in my code I want to add child for (Zebra) but this child is enter from the user and thanks
Dalek Dave 26-May-11 3:43am    
Edited for Grammar and Readability.

1 solution

You could implement an comparator that you pass to the constructor that will be used to determine where the child needs to be added. You can specify how this should be done in the comparator yourself.
http://www.javadeveloper.co.in/java-example/java-comparator-example.html[^]

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900