diff --git a/Java/TriesWithFrequencies/src/TrieFunctions.java b/Java/TriesWithFrequencies/src/TrieFunctions.java index 59a90df6..3c634b94 100644 --- a/Java/TriesWithFrequencies/src/TrieFunctions.java +++ b/Java/TriesWithFrequencies/src/TrieFunctions.java @@ -496,6 +496,26 @@ public static String pathsToJSON(List>> paths) { return res; } + //! @description Finds all words in the trie tr that start with the word searchWord. + //! @param tr a trie object + //! @param sword search word + public static List> getWords(Trie tr) { + + // Simple copy of the code below, too short and trivial to refactor at this point. + List>> paths = rootToLeafPaths(tr); + + List> res = new ArrayList<>(); + for (List> ps : paths) { + + List w = new ArrayList<>(); + + for (Map.Entry p : ps) { + w.add(p.getKey()); + } + res.add(w); + } + return res; + } //! @description Finds all words in the trie tr that start with the word searchWord. //! @param tr a trie object