mirror of
https://github.com/krahets/hello-algo.git
synced 2025-12-19 07:17:54 +08:00
Fix the code of hash map chaining.
This commit is contained in:
@@ -72,12 +72,13 @@ class HashMapChaining {
|
||||
public void remove(int key) {
|
||||
int index = hashFunc(key);
|
||||
// 遍历桶,从中删除键值对
|
||||
foreach (Pair pair in buckets[index].ToList()) {
|
||||
foreach (Pair pair in buckets[index].ToList()) {
|
||||
if (pair.key == key) {
|
||||
buckets[index].Remove(pair);
|
||||
size--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
size--;
|
||||
}
|
||||
|
||||
/* 扩容哈希表 */
|
||||
|
||||
Reference in New Issue
Block a user