I need to create a tree structure which would help me to loop through the values easily. I though of creating a bean which contains the parent name and list of children.But i am stuck on how to populate the bean and on how to retrieve the values if i am going to have a list of beans.
Adding everything from root to last leaf in the list will soon start getting big. with each new number of new leaf or stem. This way you are storing things repeatedly
Rahul.p Kumar wrote:Adding everything from root to last leaf in the list will soon start getting big. with each new number of new leaf or stem. This way you are storing things repeatedly
Sorry I don't get you.I'm not trying to store the values repeatedly. I'm trying to create a tree of the TestModel objects
Hello Rahul,
I cannot use a HashMap i guess.I feel the data structure i have will do the job, but I'm having problems building the tree with list of Strings stuck on adding the children recursively.
you want to do probably like this:
at top "tree" is there. it has then a list of objects Test and Test1. Each of which has further List of objects, say Test has list of objects A and B. So nexst time an input like Test>A>C comes, first enquire list of "tree" at top. If it has Test, then further enquire in same fashion, as soon as it says it does not have that element, from there on start adding the elements.
What I'm trying to do is to create a TestModel for each String in the list and then find the parent so that it can be added to the child nodes.But for some reason it is always adding to the root node.
David and Rahul,
Thanks for all your time
P.S If i get the the findParent method working, I guess it will work fine.What do you think?
Recursion is often tricky--I usually recommend "playing computer": trace out the algorithm manually, with a paper and pencil, in order to figure stuff like this out.
David Newton wrote:Recursion is often tricky--I usually recommend "playing computer": trace out the algorithm manually, with a paper and pencil, in order to figure stuff like this out.
Did exactly that to get the recursion right. Thanks David.Thanks Rahul
Srikkanth
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Gift giving made easy with the permaculture playing cards