Question: Find and remove the next smallest value in Binary Search Tree (C#) Use the existing code, and modify the private BSTNode method to remove the

Find and remove the next smallest value in Binary Search Tree (C#)

Use the existing code, and modify the private BSTNode method to remove the next smallest value, given target number and a node to start searching at. Note that the two parameters are redundant, in that the variable smallerThanThis is the value of the BSTNode startHere. The method should then find (and remove) the BST Node that contains the value that is the next smaller value than this target value. The return value of the method should be a reference to the node that you just removed.

private BSTNode FindAndRemoveNextSmallerValue(int smallerThanThis, BSTNode startHere) { BSTNode parent = startHere; BSTNode child = startHere.Left; }

// Given the value of a node, find (and remove) the predessor node in the tree // returns the value of the predecessor node, or Int32.MinValue if no such value was found public int TestFindAndRemoveNextSmallest(int sourceNode) { BSTNode startAt = this.FindNode(sourceNode); // sourceNode should == startAt.Data, unless startAt is null) BSTNode removed = FindAndRemoveNextSmallerValue(sourceNode, startAt); if (removed != null) return removed.Data; else return Int32.MinValue; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!