I am trying to write a method called permutations. Basically, I want it to take in an integer and then return all of the permutations of the numbers from 0 to x -1. I realize this should return an array of arrays. However I am struggling to actually implement this. Can someone help me think about this in a better way? I am coding this in java. I realize this will probably be a recursion problem but other than that I am at a loss.
I thought about having two methods, one that takes in the integer and makes the first array from 0 - x-1. Then another method that takes in an array and some integer "start". This way the integer at index start will not change, but there will be swapping with the other numbers. This would be inside of a for loop so that the "start" position will change throughout the array. The only hint I have for this was that my for loop is going to recursively call the method. However I am having trouble thinking about how to actually implement this and the algorithm for the swapping.
Can someone tell me if I am thinking about this right and if they have any ideas or hints to give me? I do not have code to share since I have been white boarding the majority of my thoughts for this.