[jdom-interest] breadth first traversal, nextElement()

Azrael azrael at azrael-uk.f2s.com
Wed Aug 28 09:32:00 PDT 2002


Andres March wrote:
> How is the numbering of your diagram determined?  Would order = branch#  x level# ?  It seems strange to process the elements sequentially in this manner.  From your previous posts I inferred that 11 would be last because it is the deepest child of the last branch.  But my comprehension of your problem was incorrect.  Usually, if I was to parse an entire tree manually I would complete each branch iteratively before beginning on the next.  For example, I would hit 1,2,5,12 before starting on 3,6,7,13,14,8.
> 
> I thought about doing it the way you have written about but it never made sense to me.  You have to go back to the same element multiple times - once to process and the other times to check for children....  I've included the code I commonly use for my method.  Sorry, if it doesn't help.

That's pretty much the difference between a depth first traversal 
(in-order) and a breadth-first traversal.
My project relies on breadth-first traversal.. so it's easier to do 
that.. than alter everything else.. I think :)
I'm sure that there was a good reason for everything working out this 
way... there must be

> public void processAll(rootElem) {
>  
> 	ArrayList childrenList = rootElem.getChildren();
> 	Iterator it = childrenList.iterator();
> 	while( it.hasNext() )  {
> 		Element childElem = it.next();
> 		// do whatever you want with it 
> 		processAll(childElem);
> 
>         	}	


-- 
                 Azrael

            ("\''/").___..--'''"-._
            `0_ O  )   `-.  (     ).`-.__.`)
            (_Y_.)'  ._   )  `._ `. ``-..-'
          _..`--'_..-_/  /--'_.' .'
         ((i).-''  ((i).'  (((.-'

Of all God's creatures there is only one that cannot be made the slave 
of the lash. That one is the cat. If man could be crossed with a cat it 
would improve man, but it would deteriorate the cat.

ICQ#52944566




More information about the jdom-interest mailing list