5.3 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++) { temp = c [i]; c [i] = c [k + 1]; c [k + 1] = temp; allPermutations += recPermute (String.valueOf (c).toCharArray(), k+1); } // for return allPermutations; } // else } // method recPermute | |
| View Solution | |
| << Back | Next >> |