What is an elegant way to find all the permutations of a string. E.g. permutation for ba, would be ba and ab, but what about longer st
ba
ab
Java implementation without recursion
public Set permutate(String s){ Queue permutations = new LinkedList(); Set v = new HashSet(); permutations.add(s); while(permutations.size()!=0){ String str = permutations.poll(); if(!v.contains(str)){ v.add(str); for(int i = 0;i