Added destructor function (#702)

* Added destructor function

* Fixed hash function

* Added hash_map_chaining.c file

* Amendment submission

* Delete hash_map_chaining.c

---------

Co-authored-by: Yudong Jin <krahets@163.com>
pull/704/head
XiaChuerwu 1 year ago committed by GitHub
parent 88a746f493
commit cf0d4b32ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,6 +21,16 @@ class HashMapChaining {
buckets.resize(capacity); buckets.resize(capacity);
} }
/* 析构方法 */
~HashMapChaining() {
for (auto &bucket : buckets) {
for (Pair *pair : bucket) {
// 释放内存
delete pair;
}
}
}
/* 哈希函数 */ /* 哈希函数 */
int hashFunc(int key) { int hashFunc(int key) {
return key % capacity; return key % capacity;

Loading…
Cancel
Save