.由於裝填因子為關鍵字有個所以表長為/=
()用除留余數法哈希函數為H(key)=key %
()
()計算查找失敗時的平均查找長度必須計算不在表中的關鍵字當其哈希地址為i(≤i≤m)時的查找次數本例中m=故查找失敗時的平均查找長度為
ASLunsucc=(+++++++++)/= ASLsucc =/=
()int Delete(int h[n]int k)
// 從哈希表h[n]中刪除元素k若刪除成功返回否則返回
{i=k%// 哈希函數用上面()即H(key)=key %
if(h[i]== maxint)//maxint解釋成空地址
printf(無關鍵字%d\nk)return ()}
if(h[i]==k){h[i]=maxint return ()} //被刪元素換成最大機器數的負數
else // 采用線性探測再散列解決沖突
{j=i;
for(d=d≤nd++)
{i=(j+d)%n // n為表長此處為
if(h[i]== maxint)return (); //maxint解釋成空地址
if(h[i]==k){ h[i]=maxint return ()}
}//for
}
printf(無關鍵字%d\nk)return ()
}
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/22812.html