mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 14:18:20 +08:00 
			
		
		
		
	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>
This commit is contained in:
		@ -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;
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user