“Java retornando uma variedade comparável de travessia inorderna da árvore binária” Respostas de código

Java retornando uma variedade comparável de travessia inorderna da árvore binária

public void inOrder(TreeNode node, E[] array, int index){
    if(node == null){  // recursion anchor: when the node is null an empty leaf was reached (doesn't matter if it is left or right, just end the method call
       return;
    }
    inOrder(node.getLeft(), array, index);   // first do every left child tree
    array[index++]= node.getData();          // then write the data in the array
    inOrder(node.getRight(), array, index);  // do the same with the right child
}
Energetic Eland

Java retornando uma variedade comparável de travessia inorderna da árvore binária

TreeNode tree  // this is your tree you want to traverse
E[] array = new E[tree.size];  // the arrays length must be equivalent to the number of Nodes in the tree
int index = 0; // when adding something to the array we need an index
inOrder(tree, array, index);  // thats the call for the method you'll create
Energetic Eland

Respostas semelhantes a “Java retornando uma variedade comparável de travessia inorderna da árvore binária”

Perguntas semelhantes a “Java retornando uma variedade comparável de travessia inorderna da árvore binária”

Mais respostas relacionadas para “Java retornando uma variedade comparável de travessia inorderna da árvore binária” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código