Question: Using the binary_tree_node from textbook, write a function to meet the following specification. You do not need to check the precondition. template bool has_42(binary_tree_node *
Using the binary_tree_node from textbook, write a function to meet the following specification. You do not need to check the precondition.
template
bool has_42(binary_tree_node
* root_ptr)
// Precondition: root_ptr is the root pointer of a binary tree (but NOT NECESSARILY a search tree).
// Postcondition: The return value indicates whether 42 appears somewhere in the tree. NOTE: If the tree is empty, the function returns false.
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
