我试图做一个数据结构,基本上是一个哈希表,这是一个矢量内组成的链表。在链表的每个节点都包含链接的情况下,元素E和键K.在矢量的每个索引中,应该有一个链表。构造向量链表Struccture
我试图创建的构造函数,但我有一些麻烦,这样做,因为我不知道如何初始化我的对象包含每个矢量指数内部的链接列表。我收到的错误是如下:
Exception in thread "main" java.lang.Error: Unresolved compilation problems: List cannot be resolved to a variable K cannot be resolved to a variable E cannot be resolved to a variable list cannot be resolved to a variable Syntax error on token "=", <= expected Incorrect number of arguments for type LinkedList; it cannot be >parameterized with arguments K, E
我找要做出的表通过使用构造拿着链表中的每个索引。
谁能帮助或推着我在这一个正确的方向?到目前为止,这是我:
import java.util.*;
public class NewTable <K, E> {
private Vector <LinkedList<HashPair <K,E>>> table;
public NewTable(int capacity){
if (capacity <= 0){
throw new IllegalArgumentException("Capacity is negative.");
}
else{
table = new Vector<LinkedList<HashPair<K, E>>>(capacity);
for (int i=0;i<table.capacity();i++){
table.set(i, List<K, E> list = new LinkedList<K, E>());
}
}
}
public static void main(String[] args) {
NewTable<String, String> table = new NewTable<String, String>(5);
table.put("Good", "Food");
}
}
欢迎堆栈溢出!请[参观](http://stackoverflow.com/tour)以查看网站的工作原理和问题,并相应地编辑您的问题。另请参阅:如何创建一个最小的,完整的,并且可验证的示例](http://stackoverflow.com/help/mcve) –
@Joe C I感谢你的欢迎!我刚刚做了一些编辑,删除了所有不必要的代码,只删除了与问题有关的代码。 – Oluwatosin
此外,寻求调试帮助的问题(“为什么不是这个代码工作?”)必须包括所需的行为,特定的问题或错误以及必须的最短代码来在问题本身中重现**。没有明确问题陈述的问题对其他读者无益。 –