示例#1
0
        //get all words that start with the prefix "s"
        public List <string> get_matches(string s)
        {
            Search_Node curr_node = head;

            foreach (char c in s)
            {
                curr_node = curr_node[c];
                if (null == curr_node)
                {
                    return(null);
                }
            }
            List <string> res = new List <string>();

            foreach (int i in curr_node.pre_words)
            {
                res.Add(words[i]);
            }
            return(res);
        }
示例#2
0
        public void Add(string s)
        {
            char        last_letter = ' ';
            Search_Node curr_node   = head;
            Search_Node last_node   = head;

            foreach (char c in s)
            {
                last_node = curr_node;
                if (null == curr_node[c])
                {
                    curr_node[c] = new Search_Node();
                }
                curr_node = curr_node[c];
                curr_node.pre_words.Add(counter);
                last_letter = c;
            }
            if (!last_node[last_letter].is_a_word)
            {
                last_node[last_letter].is_a_word = true;
                words.Add(counter++, s);
            }
        }
示例#3
0
 public Search()
 {
     words   = new Dictionary <int, string>();
     counter = 0;
     head    = new Search_Node();
 }