public void AddWord(string word)
            {
                TrieNode curr = head;

                // curr = curr.GetChild(word[0], true, true);

                for (int i = 0; i < word.Length; i++)
                {
                    if (i == word.Length - 1)
                    {
                        curr = curr.GetChild(word[i], true, true);
                    }
                    else
                    {
                        curr = curr.GetChild(word[i], true);
                    }
                }

                curr.AddCount();
            }
Beispiel #2
0
        /**
         * Get the count of a partictlar word.
         * Retrieval is O (|A| * |W|), where A is the alphabet and W is the word being searched.
         */
        public int GetCount(string word)
        {
            TrieNode curr = head;

            foreach (char c in word)
            {
                curr = curr.GetChild(c);
                if (curr == null)
                {
                    return(0);
                }
            }
            return(curr.Count);
        }
            private void Create_Branches(TrieNode node, string sub_string, string input)
            {
                if (node == null || returnList.Count > 10)
                {
                    return;
                }

                sub_string = sub_string + node.data;

                if (node.GetChild(node.data, false) == null && sub_string.StartsWith(input, StringComparison.OrdinalIgnoreCase))   // Until we've reached the end of the word, keep adding
                {
                    returnList.Add(sub_string);
                }

                foreach (var n in node.children)   // Recursively generate branches for the subnodes
                {
                    Create_Branches(n, sub_string, input);
                }
            }
            public String[] getPrefix(String prefix)
            {
                String[] localResults;
                TrieNode curr = head;

                foreach (char c in prefix)
                {
                    System.Diagnostics.Debug.WriteLine(c);
                    if (curr != null)
                    {
                        curr = curr.GetChild(c);
                    }
                }

                dfs(curr, -1, prefix);
                localResults = DFSResults;
                DFSResults   = new String[10];
                nodeCount    = 0;
                max          = -1;
                return(localResults);
            }