Created
May 11, 2016 11:50
-
-
Save Aschen/51e9b2449b895b8d717f9dd36a8400b5 to your computer and use it in GitHub Desktop.
Afficher Arbre
This file contains 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
void dumpTree(int depth = 1, String indentation = "") | |
{ | |
if (this->is_leaf) | |
{ | |
System.out.println(indentation + "Node"); | |
} | |
else | |
{ | |
this->childrens[0].dumpTree(depth + 1, indentation + " "); | |
this->childrens[1].dumpTree(depth + 1, indentation + " "); | |
System.out.println(indentation + "Node" + depth); | |
this->childrens[2].dumpTree(depth + 1, indentation + " "); | |
this->childrens[3].dumpTree(depth + 1, indentation + " "); | |
} | |
} | |
On parcours récursivement l'arbre en commençant par le noeud le plus à gauche. Le noeud étant le plus profond aura la plus grande indentation. | |
En gros ça donne ça : | |
tree.dumpTree() | |
Node3 | |
Node3 | |
Node2 | |
Node3 | |
Node3 | |
Node2 | |
Node1 | |
Node2 | |
Node2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment