1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
void swap(string& s, int i, int j)
{
char temp;
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
int permuteStr(string& s, const string secret, int i, int n)
{
int j;
if (i == n) { // base case
Play p(s,0,0);
add_play(plays,secret);
return p.get_bulls();
}
else
{
for (j = i; j <= n; j++)
{
swap(s, i, j);
permuteStr(s, secret, i+1, n);
swap(s, i, j); //backtrack
}
}
}
|