Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with an assignment in the C++ language: Closest Value in a Binary Search Tree (BST) Without using an iterator, create a new

I need help with an assignment in the C++ language: image text in transcribed

Closest Value in a Binary Search Tree (BST) Without using an iterator, create a new method called closestValue()that takes an Object value and then locates a value in the tree that is closest to this Object. If the root of the tree is NULL, your method should throw an InvalidTreeArgument exception. The prototype for this method should be the following: object BST: :closestValue (Object value); For example, suppose you have the following BST 32 24 41 21 28 36 47 14 25 31 39 closestValue( 10 ) should return 14 closestValue (20) should return 21. closestValue( 42 ) should return 41. HINT: The answer returned will come from the nodes found on the path followed as if the Object parameter is getting inserted into the tree. HINT: Use recursion and pass additional parameters that keep track of the closest value you have seen so far. Pass this closest value by reference so that future recursive calls can update this parameter as additional nodes are encountered Create a test driver program that exercises each of these methods, prints the tree and the results of each operation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

What defense is appropriate?

Answered: 1 week ago