Fetch the repository succeeded.
package chap9;
public class Hash {
public static int count = 0;//冲突次数
int times;//初始的查找次数
int num = 11;//添加的元素个数
String result;
LinearNode[] list ;
public Hash(int num) {
list = new LinearNode[num];
}
public void ReceiveNum(int[] number) {
for (int i = 0; i < number.length; i++) {
LinearNode linearNode = new LinearNode(number[i]);
int index = number[i] % num;
LinearNode node =list[index];
//如果当前索引值位置为空,则放入数据
if (node == null) {
list[index] = linearNode;
times++;
}
//每次冲突的数目加一,查找的次数加一
else
{
LinearNode current = list[index];
while (current.getNext() != null)
{
current = current.getNext();
times++;
}
current.setNext(linearNode);
count++;
times++;
}
}
}
public String toString()
{
result = "平均查找次数ASL:"+(times+count)+"/"+num+"\n"+
"冲突次数为:"+ count;
System.out.println(result);
return result;
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。