Exemple #1
0
            public bool Find(string s)
            {
                bool found = false;

                if (data.Equals(s))
                {
                    found = true;
                }
                else
                {
                    if (AlphNumBST.CompareString(s, data) == CompareCharResult.FirstLess || AlphNumBST.CompareString(s, data) == CompareCharResult.Same)
                    {
                        if (leftChild != null)
                        {
                            found = leftChild.Find(s);
                        }
                    }
                    else
                    {
                        if (rightChild != null)
                        {
                            found = rightChild.Find(s);
                        }
                    }
                }

                return(found);
            }
Exemple #2
0
        private void Add(string s)
        {
            if (_root == null)
            {
                _root = new TreeNode(s);
            }
            else
            {
                if (!Find(s))
                {
                    TreeNode node = _root;

                    while (true)
                    {
                        if (AlphNumBST.CompareString(s, node.data) == CompareCharResult.FirstLess || AlphNumBST.CompareString(s, node.data) == CompareCharResult.Same)
                        {
                            if (node.leftChild == null)
                            {
                                node.leftChild = new TreeNode(s);
                                break;
                            }
                            else
                            {
                                node = node.leftChild;
                            }
                        }
                        else
                        {
                            if (node.rightChild == null)
                            {
                                node.rightChild = new TreeNode(s);
                                break;
                            }
                            else
                            {
                                node = node.rightChild;
                            }
                        }
                    }
                }
            }
        }