Esempio n. 1
0
        private static List <int> FindWord(TrieNodeCustom root, string word)
        {
            TrieNodeCustom curr = root;

            for (int i = 0; i < word.Length; i++)
            {
                if (!curr.Children.ContainsKey(word[i]))
                {
                    return new List <int> {
                               -1
                    }
                }
                ;

                curr = curr.Children[word[i]];
            }

            if (curr.Indicies.Count == 0)
            {
                return(new List <int> {
                    -1
                });
            }

            return(curr.Indicies);
        }
Esempio n. 2
0
        private static void TrieInsert(TrieNodeCustom root, string word, int start)
        {
            TrieNodeCustom curr = root;

            int i = 0;

            while (i < word.Length)
            {
                if (!curr.Children.ContainsKey(word[i]))
                {
                    curr.Children[word[i]] = new TrieNodeCustom();
                }

                curr = curr.Children[word[i]];
                i++;
            }

            curr.Indicies.Add(start);
        }
Esempio n. 3
0
        private static TrieNodeCustom buildTrie(string text)
        {
            TrieNodeCustom root = new TrieNodeCustom();

            int i = 0;

            while (i < text.Length)
            {
                int j = i;

                while (j < text.Length && text[j] != ' ')
                {
                    j++;
                }

                string word = text.Substring(i, j - 1 - i + 1);

                TrieInsert(root, word, i);

                i = j + 1;
            }

            return(root);
        }