Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. public class Arbol {
  2.  
  3. private Nodo raiz;
  4.  
  5. // construir un arbol vacio
  6. public Arbol() {
  7. raiz = null;
  8. }
  9.  
  10. // Inserta un nuevo nodo
  11. public synchronized void insertarNodo(Tanque valorInsertar) {
  12. if (raiz == null)
  13. raiz = new Nodo(valorInsertar);
  14. else
  15. raiz.insertar(valorInsertar);
  16. }
  17.  
  18. // EMPIEZA EL RECORRIDO EN PREORDEN
  19. public synchronized void recorridoPreorden() {
  20. ayudantePreorden(raiz);
  21. }
  22.  
  23. // Metodo recursivo para recorrido en preorden
  24.  
  25. private void ayudantePreorden(Nodo nodo)
  26.  
  27. {
  28. if (nodo == null)
  29. return;
  30.  
  31. System.out.print("Nombre:" + nodo.tanque.getNombreTanque() + " Capacidad: " + nodo.tanque.getCapacidad()
  32. + " Estado actual: " + nodo.tanque.getEstadoActual() + "\n"); // Mostrar datos del nodo
  33. ayudantePreorden(nodo.nodoizquierdo); // Recorre subarbol izquierdo
  34. ayudantePreorden(nodo.nododerecho); // Recorre subarbol derecho
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement