For example, in this method, the method builds an array of sorted from a BST
public E[] inOrderSort(TreeNode tree){
E[] array1 = new E[tree.size];
inOrder(tree, array1, 0);
return array1;
}
public void inOrder(TreeNode node, E[] array, int index){
if(node == null){
return;
}
inOrder(node.getLeft(), array, index);
array[index++]= node.getData();
inOrder(node.getRight(), array, index);
}
Here, how am I getting the correct result when array1 is returned in the inOrderSort method? How did Java pass the array1 declared in the method inOrderSort to the inOrder method can fill up the values for array1 in inorder sort? I thought Java is pass by reference not pass by value?