public static void Main(string[] args) { int[] inputArray = new int[] { 10, 5, 15, 2, 7, 12, 17, 1, 3, 6, 8, 11, 13, 16, 18, 4, 9 }; BinarySearchTree.BinarySearchTree bst = new BinarySearchTree.BinarySearchTree(inputArray); int[] result = bst.InOrderVisitNoRecursive(); Console.WriteLine(string.Join(",", result)); }
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()); }
static void Main(string[] args) { var tree = new BinarySearchTree.BinarySearchTree { 15, 20, 18, 7, 8, 6 }; tree.Delete(15); foreach (var item in tree) { Console.WriteLine(item); } Console.ReadKey(); }
/// <summary> /// Determines whether the current set is a superset of a specified collection. /// </summary> /// <param name="other">The collection to compare to the current set.</param> /// <returns> /// <see langword="true" /> if the current set is a superset of <paramref name="other" />; otherwise, <see langword="false" />. /// </returns> public bool IsSupersetOf(IEnumerable <T> other) { InputIEnumerableValidator(other); var otherSet = new BinarySearchTree.BinarySearchTree <T>(other); foreach (var item in otherSet.PreOrder()) { if (!set.Contains(item)) { return(false); } } return(true); }
/// <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); } } }
public void EmptyBST() { var tree = new BinarySearchTree.BinarySearchTree<int>(); Assert.AreEqual(0, tree.Count()); }
/// <summary> /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1" />. /// </summary> public void Clear() => set = new BinarySearchTree.BinarySearchTree <T>();
/// <summary> /// Initializes a new instance of the <see cref="Set{T}"/> class. /// </summary> /// <param name="collection">The collection.</param> public Set(ICollection <T> collection) : base() { InputIEnumerableValidator(collection); set = new BinarySearchTree.BinarySearchTree <T>(collection); }
/// <summary> /// Initializes a new instance of the <see cref="Set{T}"/> class. /// </summary> public Set() { set = new BinarySearchTree.BinarySearchTree <T>(); }
public void Insert_InitializationList() { var tree = new BinarySearchTree.BinarySearchTree<int>() { -1, 0, 1 }; CollectionAssert.AreEquivalent(new int[] { -1, 0, 1 }, tree.ToList()); }
public void Insert() { var tree = new BinarySearchTree.BinarySearchTree<int>(); tree.Insert(0); CollectionAssert.AreEqual(new int[] { 0 }, tree.ToList()); }