Skip to content

Commit

Permalink
Implemented getWords(Trie tr).
Browse files Browse the repository at this point in the history
  • Loading branch information
antononcube committed Oct 26, 2017
1 parent 0aabc9b commit 23990b4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Java/TriesWithFrequencies/src/TrieFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,26 @@ public static String pathsToJSON(List<List<Map.Entry<String, Double>>> 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<List<String>> getWords(Trie tr) {

// Simple copy of the code below, too short and trivial to refactor at this point.
List<List<Map.Entry<String, Double>>> paths = rootToLeafPaths(tr);

List<List<String>> res = new ArrayList<>();
for (List<Map.Entry<String, Double>> ps : paths) {

List<String> w = new ArrayList<>();

for (Map.Entry<String, Double> 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
Expand Down

0 comments on commit 23990b4

Please sign in to comment.