I have tree with the following node spec:
java.util.TreeMap<Long id, java.util.TreeMap children>
When I fill this map, I would like to retieve subtree only by id.
E.G.
Tree is:
/-4
/-2
1 < /-5
\-3<
\-6
And when I’m using my code for ID=3, I would like to return only TreeMap with parentNode = 3
Thanks in advice
You need search algorithm for trees. It’s easy with recursion. You should find all children in the root node and call the same method for each of them until you find node with ID you need and return it.
Here and here you can find examples. Difference is that you’re using a map, but it doesn’t matter. Idea is the same.