Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi!

I am trying to build a tree using java, i have about 100 strings of IP Addresses and have created trees that build a tree for each IP address string. can you please tell me how i can merge all trees into one tree?
Posted
Comments
Sergey Alexandrovich Kryukov 29-Apr-14 2:01am    
First, you need to define what do you mean by a tree merge. It's pretty much obvious with the trees of arbitrary arity, but what is that supposed to be with binary?
—SA

1 solution

Please see my comment to the question. You did not define the result of the operation you may need.

One possible definition could be this; and it would also contain a solution in it. If you made a binary tree structure for some type (IP address or string representing such address; but it should better be an IP address), you certainly have a method Add of a tree which has a parameter of the node type; it should add any arbitrary IP address to your tree. For merge, you can start with one of the trees, and traverse all nodes of another tree adding each node to the first tree, repeat it for all the trees except the first you use as a target. Naturally, the result of the merge can depend on the order of operation.

—SA
 
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