Generate all permutation of a string in recursion in java -


this question has answer here:

i know how create permutation of given string in recursive way.

lets string = "abcdefghijklmnopqrstxyz";.

i generate string of length 5 (for example) a using recursion,

meaning:

  • aaaaa
  • aaaab
  • aaaba
  • aaaca
  • zabfg

thanks in advance.

first, store unique characters using hashmap or so, transfer them list, call chars, ease of use.

your recursive method building on string. when string reaches length 5, done, , want keep it. can return string or store in global list.

in case, assume list called permutations.

void generatepermutation(string current) {     if (current.length == 5) {         permutations.add(current);     } else {         (int = 0; < chars.size(); i++) {             generatepermutation(current + chars.get(i));         }     } } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -