Exemple #1
0
        private BinarySearchTreeNode <TKey, TValue> GetNodeByKey(BinarySearchTreeNode <TKey, TValue> rootNode, TKey key)
        {
            BinarySearchTreeNode <TKey, TValue> result = null;
            var cmpResult = key.CompareTo(rootNode.Key);

            if (cmpResult > 0)
            {
                result = GetNodeByKey(rootNode.RightNode, key);
            }
            else if (cmpResult < 0)
            {
                result = GetNodeByKey(rootNode.LeftNode, key);
            }
            else
            {
                result = rootNode;
            }
            return(result);
        }
Exemple #2
0
 public void Delete(TKey key)
 {
     _root = Delete(_root, key);
 }
Exemple #3
0
 public void DeleteMin()
 {
     _root = DeleteMin(_root);
 }
Exemple #4
0
 public void Add(TKey key, TValue value)
 {
     _root = Add(_root, key, value);
 }
Exemple #5
0
 private int GetSize(BinarySearchTreeNode <TKey, TValue> node)
 {
     return(node == null ? 0 : node.Size);
 }
 public BinarySearchTreeNode(TKey key, TValue value, BinarySearchTreeNode <TKey, TValue> leftNode, BinarySearchTreeNode <TKey, TValue> rightNode, int size)
 {
     Key       = key;
     Value     = value;
     LeftNode  = leftNode;
     RightNode = rightNode;
     Size      = size;
 }