Ciao a tutti, sto cercando di svolgere un esercizio di strutture dati precisamente alberi. Devo creare un metodo ricorsivo che mi restituisca un iteratore di tutti i sottoalberi uguali strutturalmente.
Questo è il mio codice, purtroppo non stampa nulla, nemmeno le foglie.
Qualcuno può darmi un'idea? Grazie mille

Codice PHP:
public Iterator simmetrstruct(Position p)
BTPosition pp=checkPosition (p); 
NodeList l=new NodeList();   
if (
isExternal(pp))
{
 
l.insertLast(pp.element());
 return 
l.elements();
 }
 else{ if(
hasLeft(pp))

System.out.println("primo if"); 
if((
hasLeft(pp.getLeft())&& (hasRight(pp.getLeft())))) 

Iterator r=simmetrstruct(pp.getLeft()); 
while (
r.hasNext())
 
l.insertLast(r.next()); 
}
  }
 if (
hasRight(pp)) 
{
 
System.out.println("secondo if");
 if((
hasLeft(pp.getRight())&& (hasRight(pp.getRight())))) 
{
 
l.insertLast(pp.getRight()); 
Iterator r1=simmetrstruct(pp.getRight()); 
while(
r1.hasNext()) l.insertFirst(r1.next()); 
 } 

return 
l.elements();  
  }