Java Reference
In-Depth Information
A NSWERS TO S ELF -T EST Q UESTIONS
1.
Yes. The fields left and right of BinaryNode (see Segment 24.3) have BinaryNode<T> as their data type, but the
return type of the method copy is BinaryNodeInterface<T> .
2.
No. Setting rightTree to null affects only the local copy of the reference argument rightTree . An analogous
comment applies to leftTree .
3.
The data in the objects d , b , e , a , f , g , and c is displayed on separate lines.
4. public void preorderTraverse()
{
preorderTraverse(root);
} // end preorderTraverse
private void preorderTraverse(BinaryNodeInterface<T> node)
{
if (node != null )
{
System.out.println(node.getData());
preorderTraverse(node.getLeftChild());
preorderTraverse(node.getRightChild());
} // end if
} // end preorderTraverse
5.
You must cast to BinaryNode<T> three times, as follows:
BinaryNode<T> currentNode = (BinaryNode<T>)root;
currentNode = (BinaryNode<T>)currentNode.getLeftChild();
currentNode = (BinaryNode<T>)nextNode.getRightChild();
6.
27.
7.
Carole
Brett
Susan
Jennifer
Jared
Brian
Jamie
Search WWH ::




Custom Search