Last active
May 26, 2023 20:11
-
-
Save gabrielpastori1/c9db7a5a2cb97f706bdf10ec4f1502d6 to your computer and use it in GitHub Desktop.
Imprimir Arvore Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void imprimirArvore(){ | |
System.out.println("╦"); | |
imprimirArvoreRecursivamente(raiz, 0, 0); | |
} | |
public void imprimirArvoreRecursivamente(Node nodeAtual, int deep, int clean){ | |
System.out.print("║"); | |
for(int i = 0; i < deep-1; i++){ | |
System.out.print("│ "); | |
} | |
if(deep != 0){ | |
if(nodeAtual.filhoDireito == null && nodeAtual.filhoEsquerdo == null){ | |
System.out.print("└"); | |
}else{ | |
System.out.print("├"); | |
} | |
System.out.print("──"); | |
} | |
System.out.println(nodeAtual.dados); | |
if(nodeAtual.filhoEsquerdo != null) imprimirArvoreRecursivamente(nodeAtual.filhoEsquerdo, deep+1, 0); | |
if(nodeAtual.filhoDireito != null) imprimirArvoreRecursivamente(nodeAtual.filhoDireito, deep+1, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment