Question: Implement a Binary Search Tree. Your class should be templated so that it can store any sort of data. The constructor for the class should
Implement a Binary Search Tree. Your class should be templated so that it can store any sort of data. The constructor for the class should take a comparison function as a function pointer as a parameter. This function will take 2 items as parameters of the type specified in the template (passed by constant reference), and return an int (-1 if the first item is less than the second item, 0 if they are equal, 1 if item 1 is greater than item 2). You should use this function for comparisons when an item is inserted into the tree, or when searching for an item. Your Binary Search Tree should have functions for inserting, removing, and searching for data. As with the List implementations, the search in the Binary Search Tree should take an item as a parameter, and return an item if found. If not found, the function should throw an exception indicating that. For Insert, the function should take an item as a parameter and throw an exception if the item is a duplicate. Remove should take an item as a parameter, and throw an exception if the item was not found. You should use the delete by copy. with c++
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
