은 내가 대해 조금 혼란 스러워요이 학교의 과제가있다. 여기 링크 된 목록 배열
은 말하는 내용은 다음과 같습니다.는 "해싱을 위해 '체인'의 기술을 사용하는 프로그램을 작성 이 프로그램은 링크 된 각 에 대한 참조를 포함하는 배열의 길이에 읽 프로그램이 링크리스트를 생성 한 경우에서 발생 될 것이다. 또한, 저장되는 모든 값이 판독된다. 이 프로그램은 인덱스가 존재하는 해싱을위한 별도의 기능을 가진다. 이론적 '부하율'인 계산하고 인쇄 할 수 있습니다. 전체 배열을 쉽게 인쇄해야합니다. "
내가 혼란스러워하는 부분은 생성 될 각 연결된 목록에 대한 참조를 포함하는 배열의 길이로 프로그램이 읽히는 부분입니다. 여러 연결된 목록을 생성 할 수 있습니까? 그렇다면 어떻게해야합니까?
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;
}
}
코드를 영문 번역본으로 제공하면 도움이됩니다. 이제 코드를 번역 – Colleen
@Colleen. 도와 주셔서 감사합니다! –
@Colleen 그것은 지금 번역. –