Doubt about list

What is the difference between list<int>adj and list<int>*adj ?
i am getting confused!

Using the syntax,
list<int> adj;
we are creating a list of type integer.

Now coming to a runtime allocation of memory,
We can create an array at the runtime of size ā€˜nā€™ using the following syntax,
int *arr = new int[n]; // <---- (1)

Similarly, to create an array of type list, i.e. an array which contains a list of integers instead of just one integer,
we use the following syntax
list<int> *adj = new list<int>[n]; // <---- (2)

You can see in (1) WHERE I created an array of int, I just replaced that int with an another type i.e list<int> and wrote (2).
It signifies that now at every index of adj[i], we can store a list of integers.

1 Like

Thank you so much @amandeep_21. I understood ! :blush:

Happy to help. :slightly_smiling_face:

1 Like