1

I have the following class :

public class BinarySearchTree<Key extends Comparable<? super Key>, E> 
{
private BTNode<Key, E> root;
int nodeCount;

/* Constructor */

public BinarySearchTree()
{
    this.root = null;
    this.nodeCount = 0;
}

...

I have no idea how to create an instance of it in my application though...

I have tried :

BinarySearchTree myTree = new BinarySearchTree();

and also,

BinarySearchTree<Integer> myTree = new BinarySearchTree<Integer>();

Any ideas are greatly welcomed!

1
  • where is BTNode defined? Commented Jul 24, 2015 at 19:13

1 Answer 1

1

Your BinarySearchTree has two type variables in it: one called Key for the comparable key, and one called E for the type of the node content. You're specifying just one type argument in the variable declaration:

BinarySearchTree<Integer, MyType> myTree = new BinarySearchTree<Integer, MyType>();
Sign up to request clarification or add additional context in comments.

3 Comments

That is exactly what I am looking for when creating the list! Thanks One other quick question though - Do you know how I might then call my insert? it is defined as public void insert(Key key, Element e)
Something like myTree.insert(someInteger, myTypeInstance).
Thanks! This helped a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.