public class Node : IComparable
{
public object element;
public Node left;
public Node right;
public int height;
public Node(object data, Node L, Node R)
{
element = data;
left = L;
right = R;
height = 0;
}
public Node(object data)
{
element = data;
left = null;
right = null;
height = 0;
}
public int CompareTo(object obj)
{
return (this.element.CompareTo((Node)obj.element));
}
}
in this avl tree i want to compare left and right node and other balance methode for it but in start point it doesn’t support in compareto in this line of code
public int CompareTo(object obj)
{
return (this.element.CompareTo((Node)obj.element));
}
although i used interface Icomaparable..anyone tell what is missing in it it??????????????
Your
elementproperty is of type object, so it doesn’t implementIComparable. Instead you could make a generic class with the constraint that the data element of typeTmust implementIComparable<T>: