I am a beginner in c++ and I have worked on vectors just not on 2D vectors. I have surfed a lot, but data on internet is very specific related to 2D vectors. I need to build a graph given an input file and then apply Kruskal's algorithm for minimum spanning tree.
My approach:
A1, A2, A3.....An would be the first row and col of my 2d Vectors and they will
contain name. I will read the input file and start matching the names.
And then at graph[i][j] I will put the weight.
A1 A2 A3......
A1 w w w .......
A2 w w w .......
A3 w w w .......
. . . . Now I am trying something like this:
struct mat{
string name;
}
int main(){
vector<vector<mat>> matrix;
// In order to insert
vector<mat> tempVec;
tempVec[0].name = "stack";
matrix.push_back(tempVec);
}
Now I have no idea that when I do tempVec[0].name
, 0 indicates which row or col of Matrix. If it indicates row then how do I know which col is being accessed.
I mean vector.push_back(tempVec)
, assigns which position in my Matrix to data. I know I can access individual elements like Matrix[i][j]. But How can I assign weight to a particular row, col position and then access it.
Further do you think will be a good implementation for Kruskal's Method.
Please be simple in your code and explanatory. And thanks in advance.