A student wrote the following inorder method (buggy). Identi…
A student wrote the following inorder method (buggy). Identify the bug:public static void inorder(BinaryTreeNode node) { if (node.getLeft() != null) inorder(node.getLeft()); System.out.print(node.element + ” “); if (node.getRight() == null) inorder(node.getRight()); } What is the bug?
Read DetailsThe LinkedTree.iterator() implementation builds a snapshot v…
The LinkedTree.iterator() implementation builds a snapshot via preorderSubtree(root, snapshot). Given the implementation below, what order will the iterator return elements?private void preorderSubtree(Node node, List snapshot) { if (node == null) return; snapshot.add(node.getElement()); for (Node child : node.children) preorderSubtree(child, snapshot); }
Read Details