Assuming a Node class
class Node
{
int element;
Node left, right;
Node(int el, Node left, Node right)
{
element = el;
this.left = left;
this.right = right;
}
}
Write a method int numberLeaves(Node tree) that returns the number of leaves in the binary tree whose root is tree.
Assuming a Node class
class Node
{
int element;
Node left, right;
Node(int el, Node left, Node right)
{
element = el;
this.left = left;
this.right = right;
}
}
Write a method int size(Node tree) that returns the number of nodes in the binary tree whose root is tree.
int size(Node tree) {
if(tree == null) {
return 0;
}
return 1 + size(tree.left) + size(tree.right);
}
Add the following new method in the BST class.
/** Returns the number of nodes in this binary tree */
public int getNumberOfNodes()
Requirements:
* Copy constructor is defined by some authors as simply a constructor that accepts an object of the same class as an argument.