Suppose we are implementing a binary tree as a linked structure of BinaryTreeNode objects. Write a method that will print out all of the nodes of tree via a preorder traversal. You may assume that the class has a reference to a BinaryTreeNode object called root. In addition, your method may take a reference to a BinaryTreeNode object as a parameter.
What will be an ideal response?
```
public void preorder(BinaryTreeNode root)
{
System.out.println(root.getElement());
if(root.getLeftChild() != null)
preorder(root.getLeftChild());
if(root.getRightChild() != null)
preorder(root.getRightChild());
}
```
Computer Science & Information Technology
You might also like to view...
Existing text in a document can not be converted to a numbered list
Indicate whether the statement is true or false
Computer Science & Information Technology
To use files that have been compressed, you must first ________ them
A) extract B) uncontract C) decompress D) unshrink
Computer Science & Information Technology