-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutation.java
More file actions
27 lines (25 loc) · 659 Bytes
/
Copy pathPermutation.java
File metadata and controls
27 lines (25 loc) · 659 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class Permutation {
static int count =0;
private int[] swap(int[] A,int i,int j){
int temp;
temp = A[i];
A[i] = A[j];
A[j] = temp;
return A;
}
public void permutations(int[] A, int start, int end){
int n=A.length, i,j, temp;
if(start == end){
for(j=0;j<A.length;j++){
System.out.print(A[j]);
count++;
}
System.out.println(" " + count);
}
for(i=start;i<=end;i++){
A = swap(A, start, i);
permutations(A, start+1, end);
A = swap(A, i, start);
}
}
}