Hi, I read a block of code, like:
class Graph
{
public:
int V; // number of vertices
vector *adj; //adjacency list
Graph(int V);
void addEdge(int x, int y);
bool isRoute(int x, int y);
};
// Constructor
Graph::Graph(int V)
{
this->V = V;
this->adj = new vector[V];
}
// add a directed edge from x to y
void Graph::addEdge(int x, int y) {
adj[x].push_back(y);
}
int main() {
Graph g(6);
g.addEdge(5, 2);
g.addEdge(5, 0);
g.addEdge(4, 0);
g.addEdge(4, 1);
g.addEdge(2, 3);
g.addEdge(3, 1);
}
I wonder the adj is a pointer that points to a Vector object, and a vector object I think it's like an one-dimensional array, but the addEdge() operation, adj[x].push_back(y),it make another array[x,y]. in Main(), the structure of the vector object, seems like: [5,2,0] [4,0,1] [2,3] [3,1] Then this is not an one-dimensional array.so this is a Vector object, or 4 vector objects? Thanks