Java 链表数组
我有一个学校作业,我有点困惑 它是这么说的: “编写一个使用“链接”技术进行哈希的程序。 程序将读入一个数组的长度,该数组将包含对每个数组的引用 将生成的链表。此外,将读取要存储的所有值。 该程序应有一个单独的函数,用于在索引存在的地方进行散列。当该程序生成链表时,将计算并打印理论“负载系数”。整个数组应易于打印。” 我感到困惑的是,程序将读取一个数组的长度,其中包含对将生成的每个链表的引用。是否可以生成多个链接列表?那样的话,你怎么做 这是我被告知要使用的类:Java 链表数组,java,list,hash,linked-list,Java,List,Hash,Linked List,我有一个学校作业,我有点困惑 它是这么说的: “编写一个使用“链接”技术进行哈希的程序。 程序将读入一个数组的长度,该数组将包含对每个数组的引用 将生成的链表。此外,将读取要存储的所有值。 该程序应有一个单独的函数,用于在索引存在的地方进行散列。当该程序生成链表时,将计算并打印理论“负载系数”。整个数组应易于打印。” 我感到困惑的是,程序将读取一个数组的长度,其中包含对将生成的每个链表的引用。是否可以生成多个链接列表?那样的话,你怎么做 这是我被告知要使用的类: public class Enk
public class EnkelLenke {
private Node head = null;
private int numOfElements = 0;
public int getNum()
{
return numOfElements;
}
public Node getHead()
{
return head;
}
public void insertInFront(double value)
{
head = new Node (value, head);
++numOfElements;
}
public void insertInBack(double value)
{
if (head != null)
{
Node this = head;
while (this.next != null)
this = this.next;
this.next = new Node(value, null);
}
else
head = new Node(value, null);
++numOfElements;
}
public Node remove(Node n)
{
Node last = null;
Node this = head;
while (this != null && this != n)
{
last = this;
this = this.next;
}
if (this != null)
{
if (last != null)
last.next = this.next;
else
head = this.next;
this.next = null;
--numOfElements;
return this;
}
else
return null;
}
public Node findNr(int nr)
{
Node this = head;
if (nr < numOfElements)
{
for (int i = 0; i < nr; i++)
this = this.next;
return this;
}
else
return null;
}
public void deleteAll()
{
head = null;
numOfElements = 0;
}
public String printAllElements() {
String streng = new String();
Node this = head;
int i = 1;
while(this != null)
{
streng = streng + this.element + " ";
this = this.findNext();
i++;
if(i > 5)
{
i = 1;
streng = streng + "\n";
}
}
return streng;
}
public double getValueWithGivenNode (Node n)
{
Node this = head;
while (this != null && this != n)
{
this = this.next;
}
if (this == n)
return this.element;
else
return (Double) null;
}
}
public class Node {
double element;
Node next;
public Node(double e, Node n)
{
element = e;
next = n;
}
public double findElement()
{
return element;
}
public Node findNext()
{
return next;
}
}
公共类EnkelLenke{
私有节点头=null;
私有int numOfElements=0;
公共int getNum()
{
返回元素;
}
公共节点getHead()
{
回流头;
}
公共空白插入界面(双值)
{
head=新节点(值,head);
++天体元素;
}
公共void insertInBack(双值)
{
if(head!=null)
{
这个节点=头部;
while(this.next!=null)
this=this.next;
this.next=新节点(值,null);
}
其他的
head=新节点(值,空);
++天体元素;
}
删除公共节点(节点n)
{
节点last=null;
这个节点=头部;
while(this!=null&&this!=n)
{
last=这个;
this=this.next;
}
如果(此!=null)
{
if(last!=null)
last.next=this.next;
其他的
头=这个。下一个;
this.next=null;
--天体元素;
归还这个;
}
其他的
返回null;
}
公共节点findNr(内部编号)
{
这个节点=头部;
if(nr5)
{
i=1;
强度=强度+“\n”;
}
}
回报强度;
}
公共双getValueWithGivenNode(节点n)
{
这个节点=头部;
while(this!=null&&this!=n)
{
this=this.next;
}
如果(此==n)
返回此.element;
其他的
返回(双)空;
}
}
公共类节点{
双元素;
节点下一步;
公共节点(双e,节点n)
{
元素=e;
next=n;
}
公共双findElement()
{
返回元素;
}
公共节点findNext()
{
下一步返回;
}
}
您的数据结构如下所示(其中“LL”是一个链表):
在每个数组索引处,都有一个对象的链接列表,这些对象散列到该索引
是否可以生成多个链接列表?那样的话,你怎么做
对。创建数组,并将每个元素初始化为新的链表
EnkelLenke[] a = new EnkelLenke[N];
for ( int i = 0; i < N; i++ ) {
a[i] = new EnkelLenke();
}
EnkelLenke[]a=新的EnkelLenke[N];
对于(int i=0;i
您的数据结构如下所示(其中“LL”是一个链表):
在每个数组索引处,都有一个对象的链接列表,这些对象散列到该索引
是否可以生成多个链接列表?那样的话,你怎么做
对。创建数组,并将每个元素初始化为新的链表
EnkelLenke[] a = new EnkelLenke[N];
for ( int i = 0; i < N; i++ ) {
a[i] = new EnkelLenke();
}
EnkelLenke[]a=新的EnkelLenke[N];
对于(int i=0;i
如果您提供代码的英文翻译,这会有所帮助。@Colleen现在就翻译代码。谢谢你的帮助!谢谢Alexander,虽然看起来Camilla在我看到这个之前得到了她需要的帮助:)如果你提供代码的英文翻译,那会有帮助。@Colleen现在翻译代码。谢谢你的帮助!谢谢亚历山大,尽管看起来卡米拉在我看到这个之前得到了她需要的帮助:)