I have following code written in c#.In which I am printing permutation of string.
void Main()
{
RecPermute("", "abc");
}
void RecPermute(string soFar, string rest) {
if (rest == "") {
soFar.Dump();
} else {
for(int i=0; i<rest.Length; i++) {
string next = soFar + rest[i];
string remaining = rest.Substring(0, i) + rest.Substring(i+1);
RecPermute(next, remaining);
}
}
}
Now I change the signature of method as below.
List<string> RecPermute(string soFar, string rest)
and change the code
List<string> RecPermute(string soFar, string rest) {
List<string> result=new List<string>();
if (rest == "") {
//soFar.Dump();
result.Add(soFar);
} else {
for(int i=0; i<rest.Length; i++) {
string next = soFar + rest[i];
string remaining = rest.Substring(0, i) + rest.Substring(i+1);
RecPermute(next, remaining);
}
}
return result;
}
The problem is that I am not getting any result.