Advertisement
Guest User

CSC 1351 permutations lab

a guest
Feb 11th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. @Override
  2. public int[][] permutation(int[] arr) {
  3. int n = arr.length;
  4. int[][] result = new int[fac(n)][n];
  5. int[][] ires;
  6. if (result.length == 1)
  7. result[0] = arr;
  8.  
  9. else
  10. {
  11.  
  12. for (int i = 0; i < arr.length; i++)
  13. {
  14. int[] sm = remove(arr, i);
  15. ires = permutation(sm);
  16. for (int[] ire : ires) {
  17. result[i] = append(ire, arr[i]);
  18.  
  19. }
  20. }
  21. }
  22.  
  23. return result;
  24.  
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement