Horje
java returning an comparable array of inorder traversal of binary tree Code Example
java returning an comparable array of inorder traversal of binary tree
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
java returning an comparable array of inorder traversal of binary tree
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
}




Java

Related
2771270897 Code Example 2771270897 Code Example
java escribir ventana grafica Code Example java escribir ventana grafica Code Example
autorest generate java client Code Example autorest generate java client Code Example
find the third largest number in an array Code Example find the third largest number in an array Code Example
java spring crudrepository generate insert instead of update Code Example java spring crudrepository generate insert instead of update Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7