Ok, so I am creating a Graph class, I am hoping to be able to run algorithms on and maybe add a gui to later on this summer when I have some free time. Right now I have an adjList that is implemented as an array of vectors (one for each vertex), each vector is a list of pointers representing edges going from each associated vertex to other vertices. It is declared as a protected member of my Graph class like so:
std::vector <Node*> *adjList;
adjList = new std::vector<Node*>[V];
I have a side question. Now here I have an array (through a pointer) of vectors that hold pointers. If instead this was not an array, but rather a pointer to just a single vector of node pointers then I could call the constructor like so:
adjList = new std::vector<Node*>(10);
This would allow me to specify a default size for the dynamic array in the vector, but it seems I cannot call the constructor, or at least can't get the syntax right when I have an array.
Now for my main concern. For each of these vectors in my pointer array I add a number of node pointers to each vector using a call to the new operator in my addVertex method. Now I need to make sure I handle deallocation of all this correctly. I believe I have an understanding of how this should work in C++, but I know pointers are tricky so I wanted to get someone to take a look before I go on adding lots to this code base. I couldn't find anything with a few searches that was quite like what I have. Here is my deallocation:
for(int i =0; i < V; i++)
for (unsigned int j = 0; j < adjList[i].size(); j++)
delete adjList[i][j];
delete adjList;
Will this get free all of the memory. Also is there an easy way for me to verify this for sure, eg. to keep a count of how much memory has been allocated using new while I am debugging?
[EDIT: Update w/ more info]
Here is a link to Google Books showing one of the algorithms I am wanting to implement given in psuedocode. This version of breadth-first search operates on an adjacency list, (an array of lists of pointers). Pointers must be used because of the attributes that are assigned to each node using the adjacency list.
I am wanting to retain these attributes from my BFS algorithm stored to with each node after it is ran. I know it is possible to do this in other ways, perhaps indexing nodes and using parallel arrays to store the attributes. But I wanted to have code that worked similar to this psuedo-code (for BFS in the link).