I have a class in which I have declared the array of list as a data member.
list <int> **listOfNodes;
I have allocated space for the pointers to lists in the constructor of the class as follows (here 'v' is the no. of lists I want, passed to the constructor as an argument.)
listOfNodes=new list<int>* [v];
for (int i = 0; i < v; ++i)
{
list<int> temp;
listOfNodes[i]=&temp; //declaring a new list and making the list pointer point to it
}
Now I have the following code inside the function for taking the input from the user and adding it to the corresponding list. For example, if user enters 2 5, I need to push_back a new entry 5 into the list with index 2, i.e, the list pointed to by listOfNodes[2].
int u,v;
cin>>u>>v;
(*(listOfNodes[u])).push_back(v);
But, somehow my code crashes on execution. Can someone please point out what I might be doing wrong.