【问题标题】:Delete Entry Hash Tables删除条目哈希表
【发布时间】:2021-06-01 23:30:37
【问题描述】:

只是想知道如何通过插入功能从哈希表中删除条目是这样的?

class HashTable{
    public int hash(int id){ return id%10;}

    private HNode[] head=new HNode[10];
    
    public  HashTable(){for(int i=0;i<10;i++)head[i]=null;}

    public  void insert(int k, String nm, int a, String g, String mOB, int c, String add, int pn)
        {      HNode temp =new HNode(k,nm,a,g,mOB,c,add,pn);
               int index=hash(k);
               temp.next=head[index];
               head[index]=temp;}
    
    
    
    public  HNode[] readHNode() {return head;}
    
    
    public  HNode search(int k)
        {     
        int index=hash(k);
        HNode temp=head[index];  
        boolean found=false;
        while(temp!=null&&found==false) {
               if (temp.key==k){found=true; break;}
               temp=temp.next;
        }
        return temp;}


}

【问题讨论】:

    标签: java hashtable multiple-entries


    【解决方案1】:

    设 x 为要移除的元素。

    言下之意: 如果 x 不存在,什么也不做。 else - 将 "x" 之前的列表(在 "head" 的相关索引中)附加到 x 之后的列表中。

    假设你有

     x1,x2,x3
    

    具有相同的哈希值“h1”。

    head[h1] 是一个包含 x1,x2,x3 的列表。

    基本上,你应该做分配:

    x1.next = x3
    

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-17
      相关资源
      最近更新 更多