예제 #1
0
        private bool Traverse(DSBinarySearchNode <int> node, int key)
        {
            if (node == null || node.Data == key)
            {
                return(true);
            }

            if (node.Left != null && node.Data > key)
            {
                return(Traverse(node.Left, key));
            }
            else
            {
                return(Traverse(node.Right, key));
            }
        }
예제 #2
0
        private void FindSpotToInsert(DSBinarySearchNode <int> node, int data)
        {
            if (node == null)
            {
                node = new DSBinarySearchNode <int>(data);
                this.Count++;
                return;
            }

            if (node.Data == data)
            {
                throw new InvalidOperationException("Can not add duplicate keys in Binary search tree");
            }

            if (node.Data > data)
            {
                FindSpotToInsert(node.Left, data);
            }
            else
            {
                FindSpotToInsert(node.Right, data);
            }
        }