У меня есть это школьное задание, о котором я немного смущен.Связанный список Array
Вот что он говорит:.
«Напишите программу, которая использует технику„цепочки“для хеширования Программа загрузит в длину массива, который будет содержать ссылку на каждого связанного список, который будет сгенерирован. Кроме того, считываются все значения, которые должны быть сохранены. Программа должна иметь отдельную функцию для хэширования, где существует индекс. Когда программа сгенерировала связанные списки, теоретический «коэффициент загрузки» для расчета и распечатки. Весь массив должен быть легко распечатан ».
То, о чем я запутался, является частью программы, которая будет считывать длину массива, которая будет содержать ссылку на каждый связанный список, который будет сгенерирован. Возможно ли создать несколько связанных списков? В таком случае, как вы это делаете?
Это классы я рассказанные использовать:
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 Теперь он переведен. –