I'm trying to write a method that returns a sub lists and each containin the max value of strigns from a larger list. I'm using iterator and backtrack recursion to achieve this, however - I'm not familiar with backtrack recursion. Any suggestions on how to make this work. Or if my code needs adjustments? This is what I have so far: private void printAnagrams(List<String> anagrams, int max, List<List<String>> listofLists) { Iterator<String> iterate = anagrams.iterator(); String word = ""; while (iterate.hasNext()) { for(int i = 0; i < anagrams.size(); i++) { word = iterate.next(); listofLists.add(new ArrayList<>()); listofLists.get(i).add(word); if (listofLists.size() == max) …

Member Avatar
Member Avatar
+0 forum 1

I'm working on an Anagram Finder program. One of the methods I'm writing introduces the concept of **recursive backtracking** which I'm completely new to. I'm hoping to get some suggestions of how this works/how to make it work. I'm trying to implement recursive backtracking in order to display a list of words from a dictionary text file to form anagrams for an input phrase. Here's what I have so far: public void printAnagrams(String phrase, int max, List<List<String>> anagrams) { if (anagrams == null) { throw new IllegalArgumentException(); } else if (max != 0) { System.out.println("..."); } else System.out.println("..."); for (List<String> …

Member Avatar
+0 forum 0

The End.