Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #java #returning #comparable #array #inorder #traversal #binary #tree
ADD COMMENT
Topic
Name
8+4 =