list - recursive anagram in java -


i having trouble implementing algorithm find anagrams in given string. method below doesn't return correct output. example, given word "abc" returns [abc, bc, c, bc, bc, c]. when should [abc, bac, bca, acb, cab, acb]

private list<string> anagramizerecursive(string word) {     if(word.length() == 0) {         return null;     }     else {         for(int = 0; < word.length()-1; i++) {             unfiltered.add(word.substring(i));             anagramizerecursive(word.substring(i+1));             unfiltered.add(word.substring(i+1));         }     }     return unfiltered; } 

for each character in original string, want move character front , add anagrams made rest of strings.

list<string> anagramrecursive(string word)   result = empty list   if word.isempty() result.add("")   else      each character c in word       each item in anagramrecursive(word-c)         result.add(c + item)   return result 

there many other ways of structuring recursion, have already.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -