3 using System
.Collections
.Generic
;
10 Dictionary
<char, TreeNode
> root
= new Dictionary
<char, TreeNode
>();
11 StringBuilder sb
= new StringBuilder(25);
13 public StringsTree(string[] nicks
)
18 public string FindApproximately(string partialNick
)
21 if (!root
.TryGetValue(partialNick
[0], out temp
))
25 sb
.Remove(0, sb
.Length
);
26 // Add first character
27 sb
.Append(partialNick
[0]);
29 for (int i
= 1; i
< partialNick
.Length
; i
++) {
36 void BuildTree(string[] nicks
)
41 private class TreeNode
44 Dictionary
<char, List
<TreeNode
>> childNodes
= new Dictionary
<char, List
<TreeNode
>>();
47 public TreeNode(TreeNode father
, char value)
53 public void AddChild(TreeNode child
)
55 if (!childNodes
.ContainsKey(child
.Value
)) {
56 List
<TreeNode
> temp
= new List
<TreeNode
>();
58 this.childNodes
.Add(child
.Value
, temp
);
60 this.childNodes
[child
.Value
].Add(child
);
70 public TreeNode Father
{