Earlier today I asked a question regarding getting every possible combinations and I was given a good hint on using a binary loop, after some thoughts into it I came up with the following code in C++:
vector<bool>binary(size,0);
bool filled=false;
while(filled==false)
{
bool setdigit=true;
for(int k=0;k<size;k++)
{
if(setdigit==true)
{
if(binary[k]==false)
{
binary[k]=true;
setdigit=false;
}
else //when the digit is already true
{
binary[k]=false;
}
}
}
for(int i=0;i<size;i++)
{
if(binary[i]==false)
{
filled=false;
break;
}
else filled=true;
}
}
The code seems to work but the way to test whether the binary increment is finished is very badly coded, how should i go to improve the exit condition or even the looping process?