How to write a correct Hash Table destructor in c++
问题 I am writing a c++ Hashtable Here is my destructor: HashMap::~HashMap() { for (int i=0; i<cap; i++) { Node* ptr = Hashtable[i]; while (ptr!=NULL) { Node* delptr; delptr=ptr; ptr=ptr->next; delete delptr; } } delete [] Hashtable; } My add function: void HashMap::add(const std::string& key, const std::string& value) { int index = hashfunction(key)%cap;; Node* ptr=Hashtable[index]; Node* newnode=new Node; if (contains(key)==false) { if (ptr == nullptr) { newnode->key=key; newnode->value=value;