1
ich mit dem Code, um einen binären Baum in einem Array zu speichern versuchen, unter:Speichern Binary Tree in ein Array
public void inorderArray(int[] array) {
inorderArray(root, array, 0);
}
private static Integer inorderArray(TreeNode root, int[] array, int index) {
// an inorder traversal that stores the items in array
if(root == null){return index;}
inorderArray(root.left, array, index);
array[index++] = root.key;
inorderArray(root.right, array, index);
return index;
}
Ich halte entweder [94, 95, 0, 0, 0, 0, 0, 0, 0, 0]
, und es ist nicht in Ordnung zu bringen.
Ich habe keine Ahnung, was ich falsch mache. Jede Hilfe wird geschätzt.
als eine Randnotiz - keine Notwendigkeit, "Integer" zurückzugeben, würde nur "int" ausreichen. –