int n = 10;
vector<int> adj[n];
Does this line create an array of vectors or a Vector of Arrays. And how is it different from
vector<vector <int>> vect;
vector<int> adj[n];
Creates an array of n vectors of ints. However, if n is not a compile time constant, this is not standard C++, which does not support variable length arrays. Some compilers may implement it as an extension.
vector<vector<int>> vect;
This creates a vector of vectors of ints.
The dimensions of the latter are no longer fixed, which makes them functionally quite different. vect can contain any number of vector<int> values.
There are also significant ramifications to using std::vector or std::array vs. raw arrays when it comes to passing results to/from functions.
nisn't a constant, the 1st code isn't valid c++.nknown at compile-time, and won't change of be updated at run-time? Then astd::array<std::vector<int>, n>could work (depending on the value ofnand whereadjis defined).std::array) has a fixed size known at compile-time. Some C++ compilers may implement C-style variable length arrays as a non-standard extension, but (if I understand correctly) that is fixed at runtime upon the creation of the array, and doesn't dynamically vary thereafter.