I have a permutation recursive array which works fine but I need to store the result not just print them out,I have to store each print out in a separate array or the whole in one array
here is the original:
public static void Permute(String soFar, String rest)
{
if (rest.isEmpty())
{
System.out.println(soFar);
}
else
{
for (int i =0; i < rest.length(); i++)
{
String next = soFar + rest.charAt(i);
String remaining = rest.substring(0,i) + rest.substring(i+1);
Permute(next,remaining);
}
}
}
and I changed it but the problem is that return arr is not proper in there I should do something else because the arr would become empty because other recursive function would be called and I don't want it
public static String Permute(String soFar, String rest,String arr)
{
if (rest.isEmpty())
{
// System.out.println(soFar);
arr+=soFar;
}
else
{
for (int i =0; i < rest.length(); i++)
{
String next = soFar + rest.charAt(i);
String remaining = rest.substring(0,i) + rest.substring(i+1);
Permute(next,remaining,arr);
}
}
return arr;
}