0
I am having trouble creating a method that returns the second largest element of a tree. My return code the largest element was like this:
public int maiorElemento () {
return maiorElemento(raiz);
}
private int maiorElemento(No i) {
int maior=i.elemento;
if(i.dir!=null) {
maior=maiorElemento(i.dir);
}
return maior;
}
I think my difficulty in creating is: in case the largest is i.dir and there is for example the element i.esq.dir (which would be the second largest).
Welcome Stenio, so we can run and bring a better answer it is interesting that you put more details of your code.
– André Lins
Where is the
i.esq.dir
in your code?– RXSD
Post the full code, this way no help
– rnd_rss