mercredi 22 février 2017

Can get nested set type to assign to a correct value

So heres my issues is that I am trying to imitate what this vector function is doing but using a set. The issue is that I can not get the inner for loop to work. When i try to insert a value to the subsetTemp variable, it says that the set expects one variable not two.

This is what I am trying to imitate

vector< vector<int> > getAllSubsets(vector<int> set)
{
vector< vector<int> > subset;
vector<int> empty;
subset.push_back( empty );

for (int i = 0; i < set.size(); i++)
{
    vector< vector<int> > subsetTemp = subset;

    for (int j = 0; j < subsetTemp.size(); j++)
        subsetTemp[j].push_back( set[i] );

    for (int j = 0; j < subsetTemp.size(); j++)
        subset.push_back( subsetTemp[j] );
}
  return subset;
}

This is the actual code:

#include <set>
#include <iostream>
#include <cstdlib>
using namespace std;
set<set<char>> getAllSubSet(set<char>set);
int main()
{
    set<char> set;
    set.insert(set.begin(),'a');
    getAllSubSet(set);
    return EXIT_SUCCESS;
}
set<set<char>> getAllSubSet(set<char> set)
{
  std::set<std::set<char>> subSet;
  std::set<char> empty;
  subSet.insert(subSet.begin(),empty);

  std::set<std::set<char>>::iterator it_outer;
  std::set<char>::iterator it_inner;

  for(it_inner = set.begin(); it_inner != set.end();it_inner++ )
  {
      std::set<std::set<char>> subsetTemp = subSet;
      for(it_outer = subsetTemp.begin();it_outer!=subsetTemp.end();it_outer++)
        subsetTemp.insert(it_outer,'a');

  }
  return subSet;
}

Im not entirely sure on how to fix this issue and have been stuck on it for quite a bit. Any help will be appreciated.

Aucun commentaire:

Enregistrer un commentaire