My teacher says that it is a bad programming practice, passing the variable that interests us as a parameter of a recursive method, eg:
int getMaior(Celula i, int maiorV)
It says that it is better to do the following method:
public int getMaior(){
return getMaior(primeiro.prox);
}
public int getMaior(Celula i){
if(i!=null){
if(i.elemento>maior) maior= i.elemento ;
maior=getMaior(i.prox);
}
return maior;
}
However, if the largest variable is not global, this method does not work.
I've also tried doing:
public int getMaior(){
return getMaior(primeiro.prox);
}
public int getMaior(Celula i){
int maior=Integer.MIN_VALUE;
if(i!=null){
if(i.elemento>maior) maior= i.elemento ;
maior=getMaior(i.prox);
}
return maior;
}
And I was not successful. Thanks in advance!