Re: Cocoa-dev Digest, Vol 6, Issue 794
Re: Cocoa-dev Digest, Vol 6, Issue 794
- Subject: Re: Cocoa-dev Digest, Vol 6, Issue 794
- From: Greg Guerin <email@hidden>
- Date: Thu, 28 May 2009 08:57:59 -0700
Mike McLaughlin. wrote:
I'm familiar with recursion; that is what prompted my query.
However, the
tree-traversal documentation at
http://devworld.apple.com/documentation/Cocoa/Conceptual/
NSXML_Concepts/Arti
cles/TraversingTree.html#//apple_ref/doc/uid/TP40001257
seems to indicate that the built-in traversal method, nextNode, is
non-recursive (in the usual sense).
Read beyond Listing 1.
The nextNode method is simply ONE method that can be used for
traversal. The rest of the documentation below Listing 1 describes
ways to perform hierarchical traversal.
This method will return non-nil until
the whole tree is finished. I was looking for some indicator that
I had
finished just a subtree. [Perhaps level will work.]
Your question is vague. You need to be specific about exactly what
this traversal will do, and in what order of nodes. Depth-first is
easy using any of the hierarchical traversals below Listing 1.
There are 2 steps to your original question:
1. Find the node that represents a desired subtree.
2. Traverse that subtree, doing something.
You can use ANY of the methods for step 1. One may be more efficient
than others. Hard to say without knowing exactly what criteria
you're using to choose the node.
Once you have the node of interest, you can traverse using the
hierarchical methods. If you insist on using nextNode, however, it
may be harder to identify the end of the subtree, because nextNode
inherently treats the nodes as flat (sequential), not hierarchical.
It's easy to identify the end of a subtree because the hierarchical
traversal just naturally ends. It won't be impossible to identify
the end of a nextNode-traversed subtree, and as you speculated, using
level would work.
-- GG
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden