public class Trie
extends java.lang.Object
implements java.lang.Iterable<java.lang.String>
Modifier and Type | Class and Description |
---|---|
class |
Trie.NodeIterator
Iterator over strings stored in the internal node structure
It traverses the node tree depth first, using coroutine with threads,
and collects all possible words in no particular order.
|
static class |
Trie.Search
A position in the node structure when looking for a word.
|
Constructor and Description |
---|
Trie() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getRandomLargeWord()
Performs a random walk in the data structure, randomly selecting
a path in each node, until reaching a leaf (a node with no descendants).
|
java.util.Iterator<java.lang.String> |
iterator()
Returns an iterator over the strings stored in the trie
|
void |
put(java.lang.String word)
Insert a word in the structure, starting from the root.
|
Trie.Search |
startSearch()
Start a word search from the root.
|
public void put(java.lang.String word)
word
- to be insertedpublic Trie.Search startSearch()
Trie.Search
instancepublic java.lang.String getRandomLargeWord()
Suggestion: Use a StringBuffer
to pass it recursively to
a Node
method to collect the word's characters
String
public java.util.Iterator<java.lang.String> iterator()
iterator
in interface java.lang.Iterable<java.lang.String>