Examlex
Given the BinaryTree class discussed in section 17.2 (partially shown below) , select an expression to complete the static recursive helper method countLeaves, which returns the number of leaf nodes in the binary tree rooted at node n. public class BinaryTree
{
Private Node root;
Public BinaryTree()
{
Root = null;
}
Public BinaryTree(Object rootData, BinaryTree left, BinaryTree right)
{
Root = new Node() ;
Root.data = rootData;
Root.left = left.root;
Root.right = right.root;
}
Class Node
{
Public Object data;
Public Node left;
Public Node right;
}
Public int countLeaves()
{
Return countLeaves(root) ;
}
Public static int countLeaves (Node n)
{
If (n == null)
{
Return 0;
}
Else if (_____________________)
{
Return 1;
}
Else
{
Return countLeaves(n.left) + countLeaves(n.right) ;
}
}
}
Q2: To maintain compatibility with pre-generic Java, type
Q3: The _ interface toolkit has a large
Q9: In Big-Oh notation, selection sort is a(n)
Q22: Consider the following code snippet: ArrayList<Coin> coins1
Q37: Examine the SharedData class shown below. Suppose
Q50: Which argument(s) present(s) the best case(s) for
Q72: What type of program can you use
Q78: Which of the following actions must be
Q84: A doubly-linked list requires that each node
Q103: Consider the following binary search tree diagram: