Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. public class Permutation {
  2.     // sinh hoan vi cua tap n phan tu
  3.     static int arr[] = { 1, 3, 4,6,7,4 };
  4.     static int n;
  5.     public static void swap(int i, int j) {
  6.        int tmp=arr[i];
  7.        arr[i]=arr[j];
  8.        arr[j]=tmp;
  9.        
  10.     }
  11.  
  12.     public static void createPermution(int index){
  13.         if(index==n){
  14.             print();
  15.             return;
  16.         }
  17.           for(int i=index;i<n;i++){
  18.             swap(index,i);
  19.             createPermution(index+1);
  20.             swap(index,i);
  21.           }
  22.        
  23.     }
  24.     public static void print(){
  25.         for (int i : arr) {
  26.             System.out.print(" "+i);
  27.         }
  28.         System.out.println("\n");
  29.     }
  30.     public static void main(String[] args) {
  31.       n=arr.length;
  32.       createPermution(0);
  33.     }
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement