Beispiel #1
0
        private void Add(string s, int pos, ref Node node, object item)
        {
            if (node == null) { node = new Node(s[pos], false); }

            if (s[pos] < node.m_char) { Add(s, pos, ref node.m_left, item); }
            else if (s[pos] > node.m_char) { Add(s, pos, ref node.m_right, item); }
            else
            {
                if (pos + 1 == s.Length)
                {
                    node.m_wordEnd = true;
                    node.item = item;
                }
                else
                {
                    Add(s, pos + 1, ref node.m_center, item);
                }
            }
        }
Beispiel #2
0
 public void Clear()
 {
     m_root = null;
 }
Beispiel #3
0
        private void FindSuggestions(string s, List<object> suggestions, Node node)
        {
            if (node == null)
            {
                return;
            }

            if (node.m_wordEnd == true)
            {
                suggestions.Add(node.item);
            }

            FindSuggestions(s, suggestions, node.m_left);
            FindSuggestions(s + node.m_char, suggestions, node.m_center);
            FindSuggestions(s, suggestions, node.m_right);
        }