Sou novo em java, e estou tendo dificuldade de achar o menor e maior valor que outro valor passado para a função. Se alguem poder me ajudar, agradeço desde já .
Qual o contexto?
O que você está tentando fazer?
O que você já fez?
Parece que deu certo vou postar o codigo se alguem tiver alguma coisa para melhor me avise.
public AvlNode Menor(Double x ){
AvlNode t;
double menor=Double.MAX_VALUE;
if (isEmpty()){
System.out.println(“Árvore vazia!”);
return null;
}
else{
t = minimo(raiz,x,menor);
return t;
}
}
private AvlNode minimo(AvlNode t,Double x ,Double menor){
if(t !=null){
System.out.println( t.info);
System.out.println(menor);
if( t.info > x && menor > t.info){
System.out.println("oi");
menor = t.info;
aux=t;
}
}
if( t.info <= x ){
if (t.direito==null)return null;
this.minimo(t.direito,x,menor);
}else {
if(t.esq==null)return t;
else
this.minimo(t.esq,x,menor);
}
return aux;
}