Generic Binary Search Tree, Allowing Only Comparable Elements
Hi, everyone. I'm new to generics, and I can't figure out exactly how to do this. I need to implement a binary search tree. This is easy enough to do if I only allow it to contain integers, but I want it to accept any object that implements Comparable. So normally, the class definition would look something like this:
Code:
public class BinarySearchTree {
...
}
I want to make it a BinarySearchTree that can, and must, be assigned to a particular Comparable type. Something like this:
Code:
public class BinarySearchTree<Comparable> {
...
}
I know that this isn't the correct way to do it, though. How can I do this?