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.addNode(6);
tree.addNode(12);
tree.addNode(8);
tree.minimumVal(???); // what do I pass into the parenthesis? it requires a Node reference
}
Stupid question probably but any help would be great.