@Test public void testRecursiveInorder() { assertInorder(recursiveInorder(root)); }
public static <E> List<E> recursiveInorder(BinaryTreeNode<E> root) { List<E> visited = new ArrayList<>(); if (root.leftChild() != null) { visited.addAll(recursiveInorder(root.leftChild())); } visited.add(root.data()); if (root.rightChild() != null) { visited.addAll(recursiveInorder(root.rightChild())); } return visited; }
BinaryTreeWalker { public static <E> List<E> recursiveInorder(BinaryTreeNode<E> root) { List<E> visited = new ArrayList<>(); if (root.leftChild() != null) { visited.addAll(recursiveInorder(root.leftChild())); } visited.add(root.data()); if (root.rightChild() != null) { visited.addAll(recursiveInorder(root.rightChild())); } return visited; } }
BinaryTreeWalker { public static <E> List<E> recursiveInorder(BinaryTreeNode<E> root) { List<E> visited = new ArrayList<>(); if (root.leftChild() != null) { visited.addAll(recursiveInorder(root.leftChild())); } visited.add(root.data()); if (root.rightChild() != null) { visited.addAll(recursiveInorder(root.rightChild())); } return visited; }  }
BinaryTreeWalker { public static <E> List<E> recursiveInorder(BinaryTreeNode<E> root) { List<E> visited = new ArrayList<>(); if (root.leftChild() != null) { visited.addAll(recursiveInorder(root.leftChild())); } visited.add(root.data()); if (root.rightChild() != null) { visited.addAll(recursiveInorder(root.rightChild())); } return visited; }  static List<E> iterativeInorder(BinaryTreeNode<E> root); static List<E> recursiveInorder(BinaryTreeNode<E> root); }
BinaryTreeWalker { public static <E> List<E> recursiveInorder(BinaryTreeNode<E> root) { List<E> visited = new ArrayList<>(); if (root.leftChild() != null) { visited.addAll(recursiveInorder(root.leftChild())); } visited.add(root.data()); if (root.rightChild() != null) { visited.addAll(recursiveInorder(root.rightChild())); } return visited; }  static List<E> iterativeInorder(BinaryTreeNode<E> root); static List<E> recursiveInorder(BinaryTreeNode<E> root); static final Logger LOGGER; }