Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication3;
- public class Permutation {
- public static int count = 0;
- public static void permute(char[] a, int l, int r){
- int i;
- if (l == r) {
- count += 1;
- System.out.println(a);
- }
- else {
- for (i = l; i <= r; i++){
- char temp = a[l];
- a[l] = a[i];
- a[i] = temp;
- permute(a, l+1, r);
- char temp2 = a[l];
- a[l] = a[i];
- a[i] = temp2;
- }
- }
- }
- public static void main(String[] args){
- char[] str = {'c', 'a', 't', 'd', 'o', 'g'};
- int n = str.length;
- permute(str, 0, n-1);
- System.out.println("\nCount: " + count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement