0

I have some doubts when creating a tree in java, need to create a tree to save data of students with a maximum of 3 notes each and an id for each student. I also need you to enter a note in particular a left node show me all students who have a grade below the entered and the right node which they are most to that note. Someone could help me? I have the structure of the student and the node but I feel a bit tricky to insert nodes with their students

student

public class Alumno {
   private String rut;
   private String[] notas;

   public Alumno(String rut, String[] notas) {
     this.rut = rut;
     this.notas = notas;
   }

  public Alumno(){

  }

  public String getRut() {
    return rut;
  }

  public void setRut(String rut) {
    this.rut = rut;
  }

  public String[] getNotas() {
    return notas;
  }

  public void setNotas(String[] notas) {
     this.notas = notas;
  }

 @Override
 public String toString() {
     return "Alumno{" + "rut=" + rut + ", notas=" + notas + '}';
 }
}

Node

public class Nodo {
private Alumno dato;
private Nodo izquierdo;
private Nodo derecho;

public Nodo(Alumno dato){
    this.dato = dato;
}


public Nodo getNodoIzquierdo(){
    return izquierdo;
}

public Nodo getNodoDerecho(){
    return derecho;
}

public void setNodoIzquierdo(Nodo nodo){
    izquierdo = nodo;
}

public void setNodoDerecho(Nodo nodo){
    derecho = nodo;
}
}
5
  • If you need concept of Binary Trees to be clear, it is fine, however, if you are asking for solutions to direct problems that has been given for you to solve as part of your curriculum, then don't. Analyze the conceptual parts that you are not clear and get clarity by asking questions on the concepts. Commented Nov 25, 2014 at 13:06
  • @Ironluca Maybe you express me wrong, I just wanted to know if it is possible to enter data as a particular class, in this case Student Commented Nov 25, 2014 at 13:08
  • Ok, this is a hint, binar trees have a root node, which in most cases is a middle value. At any level in a B-Tree there is exactly two nodes, usually the left node has value less than the parent node and right node has value more than the parent node. The primary idea is to search for a value as fast as possible. In your case, the parent node will have 50 and left node would be 0-49 and right node 50-100. In your case, since there are 3 subjects the tree shall be 3 binary trees with the top node as abstract - good luck :) Commented Nov 25, 2014 at 13:49
  • @Ironluca Thanks !!, your orientation served me and I could achieve so, I would like you to leave him in response to dial, I really help your logic Commented Nov 25, 2014 at 15:47
  • Happy that the above could help, I added it as answer Commented Nov 26, 2014 at 6:03

1 Answer 1

1

Ok, this is a hint, binar trees have a root node, which in most cases is a middle value. At any level in a B-Tree there is exactly two nodes, usually the left node has value less than the parent node and right node has value more than the parent node. The primary idea is to search for a value as fast as possible. In your case, the parent node will have 50 and left node would be 0-49 and right node 51-100. In your case, since there are 3 subjects the tree shall be 3 binary trees with the top node as abstract.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.