Here is what I am trying to do I am trying to compare to values that are set up as generic values and return whether one is greater than the other and it is telling me that (E, E) cannot be applied and I don't know why. I would appreciate your help.
class TreeNode<E>
{
TreeNode<E> leftNode;
E data;
TreeNode<E> rightNode;
public TreeNode(E nodeData)
{
data = nodeData;
leftNode=rightNode=null;
}
public static <E extends Comparable< E > > int comp(E x, E y)
{
E val;
if(x.compareTo(y)>0){
return -1;
}
}
public void insert(E insertValue)
{
if(comp(insertValue,data)==-1)
{
if(leftNode == null)
leftNode = new TreeNode(insertValue);
else
leftNode.insert(insertValue);
}
else if(insertValue > data)
{
if(rightNode == null)
rightNode = new TreeNode(insertValue);
else
rightNode.insert(insertValue);
}
}
}
public class Tree< E >
{
private TreeNode root;
public Tree()
{
root=null;
}
public void insertNode(E insertValue)
{
if(root == null)
root = new TreeNode(insertValue);
else
root.insert(insertValue);
}