Skip to content

Instantly share code, notes, and snippets.

@EduardoVaca
Created June 30, 2015 18:47
Show Gist options
  • Save EduardoVaca/ddb291f031282ea09820 to your computer and use it in GitHub Desktop.
Save EduardoVaca/ddb291f031282ea09820 to your computer and use it in GitHub Desktop.
public class TreeDictionary{
private NodeTreeDictionary root;
private class NodeTreeDictionary{
char letter;
HashMap<char, NodeTreeDictionary> children;
String shortestWord;
NodeTreeDictionary(char l){
letter = l;
}
boolean hasChildrenByLetter(char letter){
return children.contains(letter);
}
NodeTreeDictionary childrenByLetter(char letter){
return children.get(letter);
}
}
public void insertWordInTreeDictionary(String word){
char [] wordLetters = word.toCharArray();
Java.util.Arrays.sort(wordLetters);
int index = 0;
NodeTreeDictionary actualNode = root;
while(index < wordLetters.length){
if(!actualNode.hasChildrenByLetter(wordLetters[index])) {
actualNode.children.puts(new NodeTreeDictionary(wordLetters[index])
}
actualNode = actualNode.childrenByLetter(wordLetters[index])
index++;
}
actualNode.shortestWord = word;
}
/** input must be sorted alphabetically */
public String findShortestWord(char [] licenceLetters){
String shortestWord;
int minimumSize = 100;
int indexWordArray = 0;
NodeTreeDictionary actualNode = root;
while(indexWordArray < licenceLetters.length){
if(actualNode == root){
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment