Пример #1
0
        private OneDIntervalSearchNode <TKey> Put(OneDIntervalSearchNode <TKey> node, TKey lowerKey, TKey upperkey)
        {
            if (node == null)
            {
                var a = new OneDIntervalSearchNode <TKey>(lowerKey, upperkey);
                return(a);
            }

            int cmp = lowerKey.CompareTo(node.LowerKey);

            if (cmp < 0)
            {
                node.LeftNode = Put(node.LeftNode, lowerKey, upperkey);
            }
            else if (cmp > 0)
            {
                node.RightNode = Put(node.RightNode, lowerKey, upperkey);
            }
            else
            {
                node.Value = string.Concat(lowerKey.ToString(), ",", upperkey.ToString());
            };

            if (node.RightNode != null && node.RightNode.MaximumEndPoint.CompareTo(node.MaximumEndPoint) > 0)
            {
                node.MaximumEndPoint = node.RightNode.MaximumEndPoint;
            }

            return(node);
        }
Пример #2
0
        public string Get(TKey lowerKey, TKey upperKey)
        {
            OneDIntervalSearchNode <TKey> x = Root;

            while (x != null)
            {
                if (Intersect(x.LowerKey, x.UpperKey, lowerKey, upperKey, x.MaximumEndPoint))
                {
                    return(x.Value);
                }
                else if (x.LeftNode == null)
                {
                    x = x.RightNode;
                }
                else if (x.LeftNode.MaximumEndPoint.CompareTo(lowerKey) < 0)
                {
                    x = x.RightNode;
                }
                else
                {
                    x = x.LeftNode;
                }
            }

            return("Not Found");
        }
Пример #3
0
 /// <summary>
 /// Insret item into a BST
 /// </summary>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public void Put(TKey lowerkey, TKey upperKey)
 {
     Root = Put(Root, lowerkey, upperKey);
 }