I am trying to get all possible permutations of an array of numbers and store it in an ArrayList but always getting same permutation with all elements of the arraylist as the default one {1, 4, 9, 11} any help please ?`
public static void main (String[] args) throws java.lang.Exception
{
int [] my_numbers = {1,4,9,11};
ArrayList<int []> permutation_results = new ArrayList<int []>();
arrayPermutations(permutation_results,my_numbers,0);
}
public static void arrayPermutations(ArrayList<int []> result ,int[]
numbers, int index){
if(index >= numbers.length - 1){
result.add(numbers);
return;
}
for(int i = index; i < numbers.length; i++){
int t = numbers[index];
numbers[index] = numbers[i];
numbers[i] = t;
arrayPermutations(result, numbers, index+1);
t = numbers[index];
numbers[index] = numbers[i];
numbers[i] = t;
}
}