public void InsertAFew()
 {
     var tree = new BinarySearchTree.BinarySearchTree<int>();
       tree.Add(-1);
       tree.Add(0);
       tree.Add(1);
       CollectionAssert.AreEquivalent(new int[] { -1, 0, 1 }, tree.ToList());
 }
Esempio n. 2
0
        /// <summary>
        /// Modifies the current set so that it contains only elements that are also in a specified collection.
        /// </summary>
        /// <param name="other">The collection to compare to the current set.</param>
        public void IntersectWith(IEnumerable <T> other)
        {
            InputIEnumerableValidator(other);

            var otherSet = new BinarySearchTree.BinarySearchTree <T>(other);
            var tempSet  = new BinarySearchTree.BinarySearchTree <T>(set.PreOrder());

            set = new BinarySearchTree.BinarySearchTree <T>();

            foreach (var item in otherSet.PreOrder())
            {
                if (tempSet.Contains(item))
                {
                    set.Add(item);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Adds an element to the current set and returns a value to indicate if the element was successfully added.
 /// </summary>
 /// <param name="item">The element to add to the set.</param>
 /// <returns>
 ///   <see langword="true" /> if the element is added to the set; <see langword="false" /> if the element is already in the set.
 /// </returns>
 public bool Add(T item)
 => set.Add(item);