PDA

View Full Version : [JAVA] albero simmetrico solo strutturalmente


AnnySa
10-04-2010, 10:54
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

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();



}
}

AnnySa
11-04-2010, 11:45
up