working with nested vectors

Hi, I wanted to write a program that used nested vectors. The nested vector would contain the sides of the triangles of the outer vector. I am not sure how to handle it.

1
2
3
4
5
6
7
vector<vector<int> sides> triangles; //empty vector
for(int i = 13; i >= 1; i--) {
   for(int j = 15- 1 - i; j>=1; j--) {
      //I am not sure how to handle the vectors here
   }
}


For clarity, the problem is "List all of the different triangles with a perimeter of 15." I apologize if I am being vague; I am not quite sure how to ask the question.

Thanks.
Last edited on
you can do it like so:
1
2
3
4
5
6
7
8
vector<vector<int> sides> triangles; //empty vector
for(int i = 13; i >= 1; i--) {
vector<int> sides;
   for(int j = 15- 1 - i; j>=1; j--) {
      sides.push_back(...);
   }
triangles.push_back(sides);
}


or if you concerned about speed:
1
2
3
4
5
6
7
vector<vector<int> > triangles; //empty vector
for(int i = 13; i >= 1; i--) {
triangles.push_back(vector<int>());
   for(int j = 15- 1 - i; j>=1; j--) {
      triangles.back().push_back(...);
   }
}

Will I have to clear the vector sides after each push_back() or will that happen by itself?
Oh wait, I think I get it now. Thanks!
Topic archived. No new replies allowed.