Re: Iterating through an n-ary tree
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Fri, 03 Nov 2006 17:56:44 GMT
"Ben Pfaff" <blp@xxxxxxxxxxxxxxx> wrote in message
news:87d584whu2.fsf@xxxxxxxxxxxxxxxxxxx
"Oliver Wong" <owong@xxxxxxxxxxxxxx> writes:
I'm sort of embarassed that this one seems to have me stumped. I want
to
write an iterator which will iterate through all the nodes (internal and
leaves) of a given n-ary tree. The order of iteration doesn't really
matter
(though I figure the easiest solution will produce either postfix or
prefix), as long as every node is returned exactly once. I'm not supposed
to
modify the tree while iterating through it. I don't think this matters,
but
I'll be coding the solution in Java.
Multiple solutions are described at:
http://adtinfo.org/libavl.html/Traversing-a-BST.html
(This is my website.)
Thanks. I read the site, and some of the algorithms there are very
interesting (e.g. the "up-and-left" versus "up-and-right" trick described in
"Better Iterative Traversal"). Unfortunately, they seem to assume a binary
search tree, whereas I have an n-ary tree, with arbitrary ordering of the
nodes (in fact, the nodes cannot be said to be ordered in any meaningful
way, as this is actually an abstract syntax tree from parsing source code).
- Oliver
.
- Follow-Ups:
- Re: Iterating through an n-ary tree
- From: Ben Pfaff
- Re: Iterating through an n-ary tree
- References:
- Iterating through an n-ary tree
- From: Oliver Wong
- Re: Iterating through an n-ary tree
- From: Ben Pfaff
- Iterating through an n-ary tree
- Prev by Date: Re: Iterating through an n-ary tree
- Next by Date: Re: Java to C port
- Previous by thread: Re: Iterating through an n-ary tree
- Next by thread: Re: Iterating through an n-ary tree
- Index(es):
Relevant Pages
|
|