5.4 Perform an execution-frames trace to determine the output from the following incorrect version of the recPermute method (from Lab 9) after an initial call to permute ("ABC");
invokes recPermute (['A', 'B', 'C'], 0);
/**
* Finds all permutations of a subarray from a given position to the end of the array.
*
* @param c an array of characters
* @param k the starting position in c of the subarray to be permuted.
*
* @return a String representation of all the permutations.
*
*/
public static String recPermute (char[ ] c, int k)
{
if (k == c.length - 1)
return String.valueOf (
c) + "\n";
else
{
String allPermutations = new String();
char temp;
for (int i = k; i < c.length; i++)
{
allPermutations += recPermute (String.valueOf (c).toCharArray(), k+1);
temp = c [i];
c [i] = c [k];
c [k] = temp;
} // for
return allPermutations;
} // else
} // method recPermute
 
 
View Solution
 
 
 
<< Back Next >>