Hi, I'm testing a script and I ran into a persistent error. The output of the program should be:
123
132
312
321
231
213
However, I just get a stack overflow error. I'm a bit lost as to what isn't running correctly.
CODE:
import java.util.Arrays;
public class RecursionTest {
private static void permute(String prefix, int[] s) {
N = s.length;
if (N == 0) {
System.out.println(prefix);
} else {
for (int i = 0; i < N; i++) {
permute(prefix + s[i], Arrays.copyOfRange(s, 0, N));
} /end for loop/ } /end if loop/}
public static int N=0;
public static void permute(int[] s) { permute("", s); } //initial call
public static void main(String[] args) {
N = Integer.parseInt(args[0]);
int[] elements = {1,2,3};
permute(elements);
System.out.println(); }//end main method
} //end RecursionTest class