Regarding class implementation of hashmap

Im not able to understand the recursive destructor call. plz explain how is it happening

Hello @aslesha.j7,

The recursive deletion will be explained in the next video during re-hashing when you would delete the current heap and create a new heap with larger size.
Thus, during that deletion it will recursively call the destructor.

To understand it better watch the next video or the video where they are explaining re-hashing.

Hope, this would help.
Give a like if you are satisfied.

I have seen the video but still Im not able to get how is it occurring

Hello @aslesha.j7,

At the time of rehashing, you are deleting the oldbuckets.
So, when compiler will execute the following statement:
delete oldbuckets[i];
where oldbuckets[I] is pointing to head of the linked list at index i.

This linked list is a linear data-structure of objects of the class node.
So, when you call Delete on a node. It also calls delete on the next node. This way delete is automatically propagated forward in the linked list. Therefore, if the list lets say 1->2->3.
3 then 2 then 1 will be deleted because each time before deleting current node delete on next node is called first.

Hope, this would help.
Give a like if you are satisfied.

Im not able to understand the destructor part. how is it being called recursively

Hey @aslesha.j7,

Let’s understand it with the help of an example:
Suppose,
oldbuckets[i] refers to or stores the address of the head node of the linked list: 2->4->8 i.e. the address of 2.

So, when the compiler executes the statement:
delete oldbuckets[i];
which means delete the node having value 2 i.e. the head of the linked list.

But, i have explained in my previous reply: delete automatically propagates forward in the linked list.

  1. before calling the destructor for the node with value 2, it iterates to the next of it i.e. node with value 4.
  2. thereafter, before calling the destructor for the node with value 4, it iterates to the next of it i.e. node with value 8.
  3. As the next of 8 is NULL. So, it first deletes the node with value 8(destructor)
  4. Then comes back to the previous node and deletes the node with value 4
  5. At last, a node with head.

This is all automatically handled by the compiler.

Hope, it is clear now.

but why does delete automatically moves forward

Hello @aslesha.j7,

This is an internal logic to delete the entire linked list.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.