I am solving a question where a function is defined as following:
vector <int> func(int a, vector<vector<int>> B[]){
// Some stuff
}
I am confused about why the second parameter is not only vector<vector> B why the extra [] part in the parameter. Can someone clarify the meaning of this parameter vector<vector> B[]?
The vector B is populated by a similar code snippet:
vector<vector<int>> B[10];
while(num--){
cin>>u>>v>>w;
vector<int> t1,t2;
t1.push_back(v);
t1.push_back(w);
B[u].push_back(t1);
t2.push_back(u);
t2.push_back(w);
B[v].push_back(t2);
}
>Solution :
B ist a static array (C-style) of 10 elements [0 .. 9]. It’s not safe and this code is a terrible mess.
Better use std::array<std::vector<str::vector<int>>, 10> B; instead to have index checking.