Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Integer nivel(T dato) {
- int n=0;
- boolean ok=false;
- if(this.getDatoRaiz() == dato)
- return n;
- else{
- ColaGenerica<ArbolGeneral<T>> q = new ColaGenerica<ArbolGeneral<T>>();
- q.encolar(this);
- q.encolar(null);
- ArbolGeneral<T> aux = new ArbolGeneral<T>();
- while(!q.esVacia()){
- aux=q.desencolar();
- if((aux == null) && (!q.esVacia())){
- q.encolar(null);
- n++;
- }
- else{
- if(aux!=null && ok==false){
- for(int i=0; i< aux.getHijos().tamanio(); i++){
- System.out.println("el elemento es");
- System.out.println(aux.getHijos().elemento(i).toString());
- if(aux.getHijos().elemento(i).equals(dato)){
- ok=true;
- System.out.println("Se encontro el elemento");
- }
- q.encolar(aux.getHijos().elemento(i));
- }
- }
- }
- }
- }
- if(ok==false)
- n=-1;
- return n;
- }
Add Comment
Please, Sign In to add comment