Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gabrielpastori1/c9db7a5a2cb97f706bdf10ec4f1502d6 to your computer and use it in GitHub Desktop.
Save gabrielpastori1/c9db7a5a2cb97f706bdf10ec4f1502d6 to your computer and use it in GitHub Desktop.
Imprimir Arvore Java
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