예제 #1
0
 /// <summary>
 /// Gets shortest words recursively starting from given TrieNode.
 /// </summary>
 private void GetShortestWords(TrieNode trieNode,
                               ICollection <string> shortestWords, StringBuilder buffer, Wrapped <int> length)
 {
     if (trieNode.IsWord)
     {
         if (buffer.Length < length.Value)
         {
             shortestWords.Clear();
             length.Value = buffer.Length;
         }
         if (buffer.Length == length.Value)
         {
             shortestWords.Add(buffer.ToString());
         }
     }
     foreach (var child in trieNode.GetChildren())
     {
         buffer.Append(child.Character);
         GetShortestWords(child, shortestWords, buffer, length);
         buffer.Length--;
     }
 }