Example #1
0
        public bool Contains(String word)
        {
            TreeNode tempNode = this.root;

            char[] charArray = word.ToCharArray();
            for (int i = 0; i < charArray.Length; i++)
            {
                TreeNode node = new TreeNode();
                node.Character = charArray[i];
                if (!tempNode.ContainsChild(node))
                {
                    return(false);
                }
                else
                {
                    tempNode = tempNode.GetChildren(charArray[i]);
                }
            }
            if (tempNode.IsWordEnd)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public bool Associate(char nextChar)
        {
            if (currNode.ContainsKey(nextChar))
            {
                step++;
                this.currNode = currNode.GetChildren(nextChar);
                if (currNode.IsWordEnd)
                {
                    this.isOccurWord = true;
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        public void Add(String word)
        {
            TreeNode tempNode = this.root;

            char[] charArray = word.ToCharArray();
            for (int i = 0; i < charArray.Length; i++)
            {
                TreeNode node = new TreeNode();
                node.Character = charArray[i];
                if (!tempNode.ContainsChild(node))
                {
                    tempNode.AppendChild(node);
                    tempNode = node;
                }
                else
                {
                    tempNode = tempNode.GetChildren(charArray[i]);
                }
            }
            tempNode.IsWordEnd = true;
        }