Mercedes

Untitled

Apr 13th, 2016
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. public Integer nivel(T dato) {
  2. int n=0;
  3. boolean ok=false;
  4. if(this.getDatoRaiz() == dato)
  5. return n;
  6. else{
  7. ColaGenerica<ArbolGeneral<T>> q = new ColaGenerica<ArbolGeneral<T>>();
  8. q.encolar(this);
  9. q.encolar(null);
  10. ArbolGeneral<T> aux = new ArbolGeneral<T>();
  11. while(!q.esVacia()){
  12. aux=q.desencolar();
  13. if((aux == null) && (!q.esVacia())){
  14. q.encolar(null);
  15. n++;
  16. }
  17. else{
  18. if(aux!=null && ok==false){
  19.  
  20. for(int i=0; i< aux.getHijos().tamanio(); i++){
  21. System.out.println("el elemento es");
  22. System.out.println(aux.getHijos().elemento(i).toString());
  23. if(aux.getHijos().elemento(i).equals(dato)){
  24. ok=true;
  25. System.out.println("Se encontro el elemento");
  26. }
  27. q.encolar(aux.getHijos().elemento(i));
  28. }
  29. }
  30. }
  31. }
  32.  
  33. }
  34. if(ok==false)
  35. n=-1;
  36.  
  37. return n;
  38. }
Add Comment
Please, Sign In to add comment