java - Efficient way to walk through an object tree? -


I have found a set of tree nodes, each of which has an ID, the collection of parenting nodes, and the collection of Hair nodes.

For a given node ID, I am searching an effective way to generate all the links passing through that node. So in a nutshell start with the node, and repeat it through all your children. If there is more than one child in a node, then create a link for each child across the children etc.

I also want to be able to do it in an 'upward' direction, through parent nodes.

Is there a simple algorithm?

EDIT: Oh, and I want to be able to output all the nodes IDs in a given series ...

Post-text "itemprop =" text ">

If you are looking for one or the first it is not more than the following (it is a deep search before).

Go to
  (node ​​node) {foreach (node ​​childNode.Children in node) {Visit (childNode); } Dust (node); }  

The problem is that there can be cycles in the graph, so the algorithm will enter infinite loops. To get around this you should remember that they either miss the hidden nodes or store it in the archive. If there is no circle in the graph - for example, if it is a tree - this Alfine algorithm will already work.

And by the way, if there are many parents of the treeoid, then this is not a tree but rather a graph node.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -