Stephen Colebourne typed the following on 07:48 PM 5/26/2002 +0100
>> > > 4.  Must tree iterators be depth-first?  The ordered
>> > > traversal for a heap tree isn't depth-first.
>> >
>> > No, but depth first is the one I needed ;-)  There are two possibilities
>> > here,
>> > a) Add extra methods for different iteration types
>> > b) Remove the comment that specifies how the iteration is done.
>>
>> I think, personally, for things like trees, either having
>>
>> depthFirstIterator()
>> bredthFirstIterator()
>>
>> or removing all iteration from the tree directly, and require
>> folks to do:
>>
>> Iterator iter = new DepthFirstIterator( tree );
>>
>> or
>>
>> Iterator iter = new BredthFirstIterator( tree );
>>
>> Just because there's no -default- way to iterate a tree, I don't
>> think having just a plain iterator() method is sufficient.
>
>I would rather keep the iterator on TreeNode. If there are only two standard
>ways to iterate then two methods would seem appropriate. But are there more
>than two ways??

I favor a single iterator() method on the interface which returns the nodes in an 
unspecified order. I'm ambivalent about having the specific breadth/depth iterator
methods on the Interface, but if it seems like there will be more than that, forget
it; keep just a single iterator() method and leave other options to implementations
rather than clutter the interface.

There's nothing wrong with having a plain iterator() method even if there's no
default way it needs to be implemented; other Collection (non-List) classes
have iterators whose return order is unspecified.

Kief


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to