Created
September 16, 2017 15:06
-
-
Save dance2die/57e7aa68fcef7a7fe8cc983d0c922422 to your computer and use it in GitHub Desktop.
Insert a word into a trie object instance
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
private void Insert(TrieNode current, string word) | |
{ | |
foreach (char c in word) | |
{ | |
current.Children.TryGetValue(c, out TrieNode node); | |
if (node == null) | |
{ | |
node = new TrieNode(); | |
current.Children.Add(c, node); | |
} | |
current = node; | |
} | |
current.IsCompleteWord = true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment