I need a way to generate all unique sub sets of length k of an array, similar to itertools.combinations() in python. I am trying to get these sets for association mining until the support is less than 2. Any sets passed 2 are proving to be a headache. Also, cannot use any STL functions for this.
Any insight would be appreciated.
Closest I could find to what my problem is here: Generate all subsets of size k (containing k elements) in Python
P.S each element in the set (array) are integers.
in main:
int temp = 0;
int setsize = 2;
int **testarray = subsets(itemset,itemsetSize,setsize);
for (int i = 0; i < 1300; i++)
{
for(int j = 0; j < 10; j++)
{
cout<<testarray[i][j];
}
}
cout<<endl;
in functions:
int** subsets (int inputArray[],int arraySize, int k)
{
size_t n = arraySize;
int **resultArray = 0;
resultArray = new int *[1000];
size_t i = (1 << k) -1;
while( !(i >> n) )
{
int pushBack = 0;
int pushBack2 = 0;
int v[500];
for (size_t j = 0; j<n; j++)
{
if (i & (1 << j))
{
v[pushBack] = inputArray[j];
pushBack++;
}
}
resultArray[pushBack2] = v;
pushBack2++;
i = (i+(i&(-i)))|(((i^(i+(i&(-i))))>>2)/(i&(-i)));
}
return resultArray;
}