Hi all, I've just started out with programming and I'm working on a Binary Tree of integers. I have the Node and BinaryTree classes almost complete, but I'm having a derp moment trying to test my minimumVal method from the main and not sure on what to pass into the parenthesis.

Part of Node class (removed add method to save space);

``````class Node
{
Node left, right;
int dataNode;

public Node(int i)
{
dataNode = i;
right = left = null;
}
}
``````

BinaryTree class (removed some traversal methods, another add method);

``````public class BinaryTree
{
Node root;

public int minimumVal(Node n)
{
if (root == null)
{
System.out.println("Tree empty.");
return 0;
}
else
{
Node curr = n;

while (curr.left != null)
curr = curr.left;

return curr.dataNode;
}
}
}
``````

How would I test to see if minimumVal worked? What's confusing me is in the Node class the constructor is requiring an int. So in my main what would I pass in? At the minute I have...

``````public static void main(String[] args)
{
BinaryTree tree = new BinaryTree();
Node tNode = new Node(???); // what do I pass in here that'll help with finding the min value?
tree.minimumVal(???); // what do I pass into the parenthesis? it requires a Node reference
}
``````

Stupid question probably but any help would be great.

well .. the first one requires an int, so you'll need to pass an int.
the second one requires a Node, so tNode should do.
but you don't have an addNode method anywhere, so remove those calls.

so:

``````Node tNode = new Node(15); // or any other int
tree.minimumVal(tNode); …``````

well, since you don't show the add method, I don't know what it's supposed to take as a parameter, but my guess is, it would be a new instance reference of Node

## All 5 Replies

well .. the first one requires an int, so you'll need to pass an int.
the second one requires a Node, so tNode should do.
but you don't have an addNode method anywhere, so remove those calls.

so:

``````Node tNode = new Node(15); // or any other int
tree.minimumVal(tNode);
``````

I have an addNode method but I didn't include it in the post to save room. It's a basic method that checks if ins is less than dataNode and if so, insert it into the left of the tree, otherwise insert it into the right or make that value the root if the tree is empty. So I'd be using that method to insert values into the Binary Tree so I don't understand what to put in the parenthesis of Node that would then go into the parenthesis of minimumVal to test it out.

well, since you don't show the add method, I don't know what it's supposed to take as a parameter, but my guess is, it would be a new instance reference of Node

Node.java;

``````  public void add(int ins)
{
if (ins < dataNode)
{
if (left == null)
left = new Node(ins);
else
}
else
{
if (right == null)
right = new Node(ins);
else
}
}
``````

BinaryTree.java;

``````    public void addNode(int ins)
{
if (root == null)
root = new Node(ins);
else