Array implementation of graph isuue

if i write statement g.addedge(100,3) in array implementation of adjacency list the program is not printing anything.why so?

@Rj.25
Hello Reechika,
please share ur code using coding blocks ide

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.

also sir is there any way in the above code that we can iterate over the dynamically allocated array without having variable which stores the last index of that array.,like in this ,if we do not have v,then how to iterate over the array.is there any way?

also sir have i written the correct destructor for the class graph?does it will lead to memory leak if i had not written it?

what is the difference between statements graph g(); and graph g; ?

Hello @Rj.25,

  1. You have yourself answered your first question that the code is creating an array of size 5. Thus it is causing error for 100 as it is an invalid index or out of the bound index.
    BTW, this is why one of the practical limitation that leads us to the answer to your other question that why should one use hashmap implementation over the array.:laughing:

  2. You must have misunderstood the concept of dynamic memory allocation.
    It is used to allocate the memory during runtime at heap so that you cannot control its deallocation and thus it’s scope.
    I would suggest you rewatch the videos on Dynamic Programing.

  3. No, it won’t lead to the memory leak. You have correctly defined it.

  4. Both the declaration will call the default constructor. The () have their significance for the parameterized constructor. So, these are just different representation for the same operation.

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

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.

Hello @Rj.25,

  1. There is no code in the URL you have shared.

  2. During dynamic allocation, you have to specify the size.
    Even if you would fixed the to a certain size,
    You would require the value of V to iterate over it.

Let me know if you still have any doubt.