Beispiel #1
0
        /// <summary>
        /// Merge two splay trees, assumes all of the items in rhs are
        /// greater than last.
        /// All of the items in rhs are transferred to this, replacing all
        /// elements in this tree greater than last. After the
        /// operator rhs IsEmpty.
        /// </summary>
        /// <param name="last">The last (greatest) element of this tree that will be preserved</param>
        /// <param name="rhs">The tree to be merged in</param>
        /// <returns>The merged result tree</returns>
        /// <exception cref="ArgumentNullException">Throws in rhs is null</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if all elements in rhs are not greater than last.</exception>
        public SplayTree <T> Merge(T last, SplayTree <T> rhs)
        {
            if (rhs == null)
            {
                throw new ArgumentNullException("rhs", "Merge attemped with null rhs SplayTree");
            }

            if (rhs.IsEmpty)
            {
                return(this);
            }

            if (comparer.Compare(last, rhs.Minimum) > 0)
            {
                throw new ArgumentOutOfRangeException("rhs", rhs, "All elements in the rhs SplayTree must be greater than last.");
            }
            Debug.Assert(comparer.Compare(last, rhs.Minimum) <= 0);

            if (IsEmpty)
            {
                root  = rhs.root;
                count = rhs.count;
                rhs.Clear();
                return(this);
            }
            Contains(last);
            root.right = rhs.root;
            count      = null; // Invalidate count
            rhs.Clear();
            return(this);
        }
Beispiel #2
0
 public void ClearTest()
 {
     int[] array = new int[] { 100, 29, 77, 59, 61 };
     tree = new SplayTree <int>(array);
     Assert.IsFalse(tree.IsEmpty);
     tree.Clear();
     Assert.IsTrue(tree.IsEmpty);
     Assert.AreEqual(0, tree.Count);
 }
Beispiel #3
0
 public void Clear()
 {
     tree.Clear();
 }