title: how to construct a tree from a tree without recursion
body: <p>I have a tree of Mangoes items, and for every item i want to apply a treatment to turn them into Apples, how can i write a method (in Java will be nice) which takes the top of the mangoes tree element and return the top of an apples Tree without recursion.</p>
  
  <p>With recursion i have something like this:</p>
  
  <pre><code>Apple transform(Mangoe ma){      
      //Construct an apple from some modified mangoes properties
      Apple ap = new Apple(...);  
      List&lt;Apple&gt; apChildren = new ArrayList&lt;Apple&gt;();
      for(Mangoe maChild:ma.getChildren())
          children.add(transform(maChild));  
      ap.setChildren(children);  
      return ap;
  }
  </code></pre>
  
  <p>How can i repeat this behaviour with a method without recursion??</p>
  
  <p>EDIT:
  i was thinking about this algorithm to solve the problem:</p>
  
  <pre><code>List&lt;Mangoe&gt; itemsToTreat = new ArrayList&lt;Mangoe&gt;();
  itemsToTreat.add(ma);
  
  while(itemsToTreat!=null){
       //Apply treatment
       //it's impossible to set the child of a created apple without recursion         
  
       //get the direct children of itemsToTreat
       itemsToTreat = getDirectChildrenOfItemsToTreat(itemsToTreat);
  
  
  }
  </code></pre>