Created
June 30, 2015 18:47
-
-
Save EduardoVaca/ddb291f031282ea09820 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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