Can somebody please help me with my Tree implementation. I have an array list with values("1.1","1.2","1.3","188.8.131.52","184.108.40.206","1.4","220.127.116.11","18.104.22.168","22.214.171.124.1.1","126.96.36.199.1.2","1.5","1.6","188.8.131.52") and I m trying to create a Tree with this data. Please find below attached my code for the same.
My tree should look like this in the picture attached.
Now I want to print the parent of each node starting from the last one, so starting at "184.108.40.206" . and but dont know to to traverse the branch 220.127.116.11 and other children of 1.4 children. Please someone help me.
PS: I am new to java so please correct me if tehre is something wrong.
It looks as if you have been guessing, and have found a class with a promising name and not looked up what it is there for, namely the tree node class.
You will have to start from scratch. Start by learning what a tree structure is. It is probably easiest to implement with an inner class which is a Node, having lfet right and value fields. That means the objects inserted must have some sort of sorting, which you can find out about in the Java Tutorials.
Joined: Sep 17, 2012
what is said is true. I m not really familiar with java and also the Data Structure concept behind that. I m in the process of learning that by doing.
In my tree i can have n number of children ideally, not just a left or right. that is why i didnt try to make a Node class. or otherwise I should make a List<Node> children, which i was not so sure of..
Agree. But once you have a 1‑level tree working, you can fill it with as many levels as you like really easily, because it has a recursive or fractal structure.
Get a common‑or‑garden binary tree working, then you can consider how to enhance it to that variable arity tree. That variable arity is unusual, so you cannot implement it unless you think very carefully about how you determine which value belongs at which level. You need very precise rules about how to achieve that.