amanyasin
Technical User
- Feb 7, 2003
- 28
Is there any method available in Boost graph liberary to calculate subsets of length N of a SET? if no please guide me how i can calculate it.
e.g.
vector type set = { a, b, c, d, e, f, g, h, i, j }
subsets of size n=2
{a, b}, {a, c} .....{b, c}.........................
subsets of size n=3
{a, b, c}, {b, c, d} .....{ c, d, e}.........................
susets of size n=4
...............
............
I tried to solve it but it is not giving all subsets
vector<char> vars;
vars.push_back('b');
vars.push_back('c');
vars.push_back('d');
vars.push_back('e');
vars.push_back('f');
vars.push_back('g');
vars.push_back('h');
int counter = 0, n=3 ; // n = {0 ,1,2,3 ....} size of the subset
cout << " \n Y = " << vars.at(0)<<"\n";
for (int i = 1; i < vars.size(); i++)
{
counter++;
cout<<" \n i = "<<i<<" counter = "<<counter;
if (i >= 1 && counter <= n){
cout << " \n ........................cond variables = " << vars.at(i);
continue;
}
if ( counter == n+1)
{
counter = 0;
i = i - n;
}
}
e.g.
vector type set = { a, b, c, d, e, f, g, h, i, j }
subsets of size n=2
{a, b}, {a, c} .....{b, c}.........................
subsets of size n=3
{a, b, c}, {b, c, d} .....{ c, d, e}.........................
susets of size n=4
...............
............
I tried to solve it but it is not giving all subsets
vector<char> vars;
vars.push_back('b');
vars.push_back('c');
vars.push_back('d');
vars.push_back('e');
vars.push_back('f');
vars.push_back('g');
vars.push_back('h');
int counter = 0, n=3 ; // n = {0 ,1,2,3 ....} size of the subset
cout << " \n Y = " << vars.at(0)<<"\n";
for (int i = 1; i < vars.size(); i++)
{
counter++;
cout<<" \n i = "<<i<<" counter = "<<counter;
if (i >= 1 && counter <= n){
cout << " \n ........................cond variables = " << vars.at(i);
continue;
}
if ( counter == n+1)
{
counter = 0;
i = i - n;
}
}