Question: Using the binary_tree_node from textbook, write an iterative function (no recursion) to meet the following specification. You do not need to check the precondition. Make
Using the binary_tree_node from textbook, write an iterative function (no recursion) to meet the following specification. You do not need to check the precondition. Make the function as efficient as possible (do not visit nodes unnecessarily):
template
int max(binary_tree_node* root_ptr)
// Precondition: root_ptr is the root pointer of a nonempty binary SEARCH tree.
// Postcondition: The return value is the largest value in the tree. 
486 Chapter 10/ Trees With the binary tree node definition in hand, we can define a small collection of functions for creating and manipulating trees. Primarily, the functions are meant to help a programmer who is writing a class that uses a binary tree to store data. The functions are similar to the linked-list functions that we wrote in Chap- ter 5 and subsequently used in linked-list versions of the bag class, sequence class, stack class, and queue class. We will start with only two functions, but we'l add more later FIGURE 10.6 The Binary Tree Node Definition A Class Definition template
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
