Here is my code:
class BinaryTree<T>
{
private node<T> Head;
public class node<T>
{
public T Data;
public node<T> right;
public node<T> left;
public node<T> parent;
...
}
...
private void insert(ref T data, node<T> parent, ref node<T> currentChild)
{
...
{
if (currentChild.Data >= data) insert(ref data, currentChild, ref currentChild.right);
else insert(ref data, currentChild, ref currentChild.left);
}
}
}
Above at point if (currentChild.Data >= data) I am getting error :
Operator ‘>=’ cannot be applied to operands of type ‘T’ and ‘T’
What do I do to resolve the error?
The classic solutions to this problem are (1) to make
TIComparable<T>, or (2) to use anIComparer<T>or a functor to your class.(1)
(2)