2
My teacher says it’s bad programming practice, passing the variable that interests us as a parameter of a recursive method, e.g.:
int getMaior(Celula i, int maiorV)
He says it’s best 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 tried to do too:
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 didn’t succeed. Thanks in advance!
Is this a queue or a list? Because the queue concept means to remove from the beginning and put at the end. If you are inspecting anything in between, then your problem is no longer a queue and degenerated into a list.
– Victor Stafusa
Also, your question is a little confused on one thing: Where is the code of the cell class?
– Victor Stafusa