Created
February 1, 2015 22:06
Gist 3 from the article autocomplete functionality using prefix trees
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
Tree prefixTree = new Tree(); | |
prefixTree.AddWord("abc"); | |
prefixTree.AddWord("abcd"); | |
prefixTree.AddWord("abcde"); | |
prefixTree.AddWord("abcdef"); | |
prefixTree.AddWord("ab123cd"); | |
prefixTree.AddWord("abc123d"); | |
prefixTree.AddWord("abc132d"); | |
string word = "abc"; | |
if (prefixTree.Find(word)) | |
{ | |
var matches = prefixTree.GetMatches("abc"); | |
Console.WriteLine("gasit"); | |
Console.WriteLine("Autocomplete:"); | |
if (matches.Count > 0) | |
foreach (var m in matches) | |
Console.WriteLine(m); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment