算法----乘法连接法散列表

本文介绍了一种基于链表解决冲突的多链式散列表实现方法。该方法使用0.618作为乘法因子进行散列计算,并提供了插入、删除及查找等基本操作。示例代码展示了如何创建一个初始大小为16的散列表,并进行一系列数据操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. packagecom.eshore.sweetop.dataframe;
  2. importjava.util.LinkedList;
  3. importcom.eshore.sweetop.data.KeyData;
  4. publicclassMultiChainedHash{
  5. LinkedList<KeyData>[]table=newLinkedList[(int)Math.pow(2,6)];
  6. publicMultiChainedHash(){
  7. }
  8. publicMultiChainedHash(inti){
  9. table=newLinkedList[(int)Math.pow(2,i)];
  10. }
  11. publicvoidinsert(KeyDatao){
  12. if(table[hash(o.getKey())]==null)
  13. table[hash(o.getKey())]=newLinkedList<KeyData>();
  14. table[hash(o.getKey())].add(o);
  15. }
  16. publicvoiddelete(KeyDatao){
  17. table[hash(o.getKey())].remove(o);
  18. }
  19. publicKeyDatasearch(intk){
  20. for(KeyDatakd:table[hash(k)]){
  21. if(kd.getKey()==k){
  22. returnkd;
  23. }
  24. }
  25. returnnull;
  26. }
  27. publicinthash(intk){
  28. doubled=k*0.6180339887;
  29. inta=(int)Math.floor(table.length*(d-(newDouble(d).intValue())));
  30. returna;
  31. }
  32. publicstaticvoidmain(String[]args){
  33. MultiChainedHashch=newMultiChainedHash(4);
  34. ch.insert(newKeyData(2));
  35. ch.insert(newKeyData(3));
  36. ch.insert(newKeyData(13));
  37. ch.insert(newKeyData(4));
  38. ch.delete(newKeyData(3));
  39. System.out.println(ch.search(13));
  40. }
  41. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值