使用泛型时创建二叉搜索树 class 的实例?
Creating an instance of a Binary Search Tree class when using generics?
我有以下 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;
}
...
虽然我不知道如何在我的应用程序中创建它的实例...
我试过了:
BinarySearchTree myTree = new BinarySearchTree();
还有,
BinarySearchTree<Integer> myTree = new BinarySearchTree<Integer>();
非常欢迎任何想法!
你的BinarySearchTree
里面有两个类型变量:一个叫做Key
用于比较键,一个叫做E
用于节点内容的类型。您在变量声明中仅指定了一个类型参数:
BinarySearchTree<Integer, MyType> myTree = new BinarySearchTree<Integer, MyType>();
我有以下 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;
}
...
虽然我不知道如何在我的应用程序中创建它的实例...
我试过了:
BinarySearchTree myTree = new BinarySearchTree();
还有,
BinarySearchTree<Integer> myTree = new BinarySearchTree<Integer>();
非常欢迎任何想法!
你的BinarySearchTree
里面有两个类型变量:一个叫做Key
用于比较键,一个叫做E
用于节点内容的类型。您在变量声明中仅指定了一个类型参数:
BinarySearchTree<Integer, MyType> myTree = new BinarySearchTree<Integer, MyType>();