Hello,
I have written a C# class for BinarySearchTree <T> where T is generic type, which creates a binary serach tree, returns true/false if it is empty, gives leftsubtree, rightsubtree, prints nodes. I want to write a search method, int search (T element), which will search the element if it already exists in the tree. For this I need to compare the element, with elements in the binary search tree. It is easy to do if elements are of specific type but for wrtiting a generic class, how do I compare two objects of type T, which is not known.
Basically, if I have two object object1, object2 of type T, and I a want to compare as follows:
if (object1.CompareTo (object2) > 0) then go to right subtree
else if ( object1.CompareTo (object2) > < 0) then go to leftsubtree
else print object1 found.
Any help will be highly appreciated.
Thanks