/// <summary> /// Clears any existing items from the specified tree, and then inserts the array of elements, ensuring that the tree is balanced and the depth minimized. /// </summary> /// <typeparam name="T">Specifies the type of items held by nodes of the tree.</typeparam> /// <param name="tree">The tree to add the elements to.</param> /// <param name="elements">The array of elements to add to the tree.</param> /// <exception cref="System.ArgumentException">The specified array of elements is empty.</exception> /// <exception cref="System.Exception">Error encountered when adding item to the tree.</exception> public void Insert <T>(IBinarySearchTree <T> tree, T[] elements) where T : IComparable <T> { if (elements.Length == 0) { throw new ArgumentException("The specified array of elements is empty.", nameof(elements)); } tree.Clear(); Array.Sort(elements); InsertRecurse(tree, elements, 0, elements.Length - 1); }
void Clear() { intTree.Clear(); RefreshOutput(); }