Beispiel #1
0
 public Tuple <int, int> EqualRange(T v)
 {
     if (!Contains(v))
     {
         return(new Tuple <int, int>(-1, -1));
     }
     return(new Tuple <int, int>(SB_BinarySearchTree <T> .LowerBound(_root, v), SB_BinarySearchTree <T> .UpperBound(_root, v) - 1));
 }
Beispiel #2
0
    public T ElementAt(int k)
    {
        var node = SB_BinarySearchTree <T> .FindByIndex(_root, k);

        if (node == null)
        {
            throw new IndexOutOfRangeException();
        }
        return(node.Value);
    }
Beispiel #3
0
 public override void Insert(T v)
 {
     if (_root == null)
     {
         _root = new SB_BinarySearchTree <T> .Node(v);
     }
     else
     {
         _root = SB_BinarySearchTree <T> .Insert(_root, v);
     }
 }
Beispiel #4
0
 public virtual void Insert(T v)
 {
     if (_root == null)
     {
         _root = new SB_BinarySearchTree <T> .Node(v);
     }
     else
     {
         if (SB_BinarySearchTree <T> .Find(_root, v) != null)
         {
             return;
         }
         _root = SB_BinarySearchTree <T> .Insert(_root, v);
     }
 }
Beispiel #5
0
 public List <T> ToList()
 {
     return(new List <T>(SB_BinarySearchTree <T> .Enumerate(_root)));
 }
Beispiel #6
0
 public int UpperBound(T v)
 {
     return(SB_BinarySearchTree <T> .UpperBound(_root, v));
 }
Beispiel #7
0
 public int Count(T v)
 {
     return(SB_BinarySearchTree <T> .UpperBound(_root, v) - SB_BinarySearchTree <T> .LowerBound(_root, v));
 }
Beispiel #8
0
 public bool Contains(T v)
 {
     return(SB_BinarySearchTree <T> .Contains(_root, v));
 }
Beispiel #9
0
 public void Remove(T v)
 {
     _root = SB_BinarySearchTree <T> .Remove(_root, v);
 }
Beispiel #10
0
 public void Clear()
 {
     _root = null;
 }
Beispiel #11
0
 public int Count()
 {
     return(SB_BinarySearchTree <T> .Count(_root));
 }