2d vector data combination
hi i need help to arrange a 2d vector data combination . i don't know how to ask this . in the code below i created a small version of what i want but when the vector get bigger what i do i can't think an other way
Code:
#include <iostream>
#include <vector>
#include<string>
using namespace std;
int main() {
vector<vector<string>> Data;
vector<string> a;
Data.push_back(a);
Data.push_back(a);
Data.push_back(a);
Data[0].push_back("0af5d24d");
Data[0].push_back("45f2r");
Data[0].push_back("245gd");
Data[0].push_back("0");
Data[0].push_back("02");
Data[1].push_back("df5");
Data[1].push_back("0");
Data[1].push_back("245s1");
Data[2].push_back("754g5h");
Data[2].push_back("f2g1fg45f5");
Data[2].push_back("125");
Data[2].push_back("24415");
for (int i = 0; i < Data[0].size(); i++) {
for (int j = 0; j < Data[1].size(); j++) {
for (int k = 0; k < Data[2].size(); k++) {
cout << Data[0][i] << Data[0][j] << Data[0][k] << endl;
// add all 3 vector data into a 1d char array
}
}
}
return 0;
}
Re: 2d vector data combination
Code:
for (int i = 0; i < Data[0].size(); i++) {
for (int j = 0; j < Data[1].size(); j++) {
for (int k = 0; k < Data[2].size(); k++) {
cout << Data[0][i] << Data[0][j] << Data[0][k] << endl;
There seems to be a problem with this code. j is from 0 to Data[1].size(), but in the cout statement j is used with Data[0] - same issue with k?? This code only appears to work because in the example Data[0] has more elements present than either Data[1] or Data[2]. But when Data[0] has fewer elements... Do you mean
Code:
cout << Data[0][i] << Data[1][j] << Data[2][k] << endl;
Re: 2d vector data combination
yes your right sorry :) . how can i code the same functionality for big vector ( this vector only have size = 3 , what if i have a vector size that above 1000 )
Re: 2d vector data combination
Quote:
what if i have a vector size that above 1000
Apart from the coding nightmare (although you could write a program to generate the code that could then be included in the main program), have you considered the complexity of this. Even if this was re-done using recursion somehow, the run-time complexity ...
What are you trying to achieve?
Re: 2d vector data combination
:) run-time complexity is not a problem i am a very patient it not a problem its run over a month or more because i need to find a single answer if there any way to solve this problem plz show me . if its successful i will show you a cool thing
Re: 2d vector data combination
Yes, but what are you trying to achieve?
Re: 2d vector data combination
something impossible . trust me its going to be cool plz help
Re: 2d vector data combination
As don't know the purpose and the usage of the code, we can't provide further assistance.