So I've been wracking my brain over this for a while and, while the code works, it prints it in the absolute wrong order. I feel like I'm missing something so I could use an extra pair of eyes.
void recursiveBitPatterns(ArrayList<String> subsets, int n)
{
if (n==1)
{
subsets.add("0");
subsets.add("1");
return;
}
recursiveBitPatterns(subsets, n-1);
int asize = subsets.size();
for(int i=0; i<asize; i++)
{
String nsub = subsets.get(i);
subsets.set(i, nsub +"0");
subsets.add(nsub + "1");
}
}
It seems to be setting the second element of the arraylist to 1 but not overwriting it in the loop.
This prints:
000 100 010 110 001 101 011 111
Any help would be appreciated