Skip to content

Instantly share code, notes, and snippets.

@paratechnical
Created February 1, 2015 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paratechnical/73e23553a8533489ffcc to your computer and use it in GitHub Desktop.
Save paratechnical/73e23553a8533489ffcc to your computer and use it in GitHub Desktop.
Gist 3 from the article autocomplete functionality using prefix trees
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