[Vala] Recursive foreaching



I have a tree of nodes, something like this in pseudocode:
class Node
 ArrayList kidnodes
 Node parent

So - each node has kids and a parent.

I find myself wanting to foreach over the tree from code that is not within a Node.

Right now, I'm doing this kind of thing:

class Node
  ...
  public void walk( somelist)
    foreach(kid in kidnodes)
      somelist.add (kid) //visit.
      walk( somelist )

Then, in some other object:
var list = somelist
somenode.walk(l)
//now i can foreach through "list"

Is there some way I can do:

somenode = rootnode; //say
foreach( node in somenode)
  visit(node)

so that it visits the nodes like walk does?



\d


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]