Beispiel #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);
            }
        }
Beispiel #2
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;
        }