Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Hashtable;
- public class StringLib {
- static void permutation(String str, int length, StringBuffer output, boolean[] used, int position ){
- if (position==length){
- System.out.println(output.toString());
- return;
- }
- else{
- for(int i=0;i<length;i++){
- /* skip already used characters */
- if (used[i]) continue;
- /* add fixed character to output, and mark it as used */
- output.append(str.charAt(i));
- used[i]=true;
- /* permute over remaining characters starting at position+1 */
- permutation(str,length,output,used,position+1);
- /* remove fixed character from output, and unmark it */
- output.deleteCharAt(output.length()-1);
- used[i]=false;
- }
- }
- }
- public static void permute(String str){
- int length=str.length();
- boolean[] used=new boolean[length];
- StringBuffer output=new StringBuffer(length);
- permutation(str,length,output,used,0);
- }
- public static void main(String[] args){
- permute("bic");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement