Question: header file #ifndef BINTREE _ H #define BINTREE _ H #include / / Provides NULL and size _ t namespace main _ savitch _ 1

header file
#ifndef BINTREE_H
#define BINTREE_H
#include // Provides NULL and size_t
namespace main_savitch_10
{
template
class binary_tree_node
{
public:
// TYPEDEF
typedef Item value_type;
// CONSTRUCTOR
binary_tree_node(
const Item& init_data = Item(),
binary_tree_node* init_left = NULL,
binary_tree_node* init_right = NULL
)
{
data_field = init_data;
left_field = init_left;
right_field = init_right;
}
// MODIFICATION MEMBER FUNCTIONS
Item& data(){ return data_field; }
binary_tree_node*& left(){ return left_field; }
binary_tree_node*& right(){ return right_field; }
void set_data(const Item& new_data){ data_field = new_data; }
void set_left(binary_tree_node* new_left){ left_field = new_left; }
void set_right(binary_tree_node* new_right){ right_field = new_right; }
// CONST MEMBER FUNCTIONS
const Item& data() const { return data_field; }
const binary_tree_node* left() const { return left_field; }
const binary_tree_node* right() const { return right_field; }
bool is_leaf() const
{
return (left_field == NULL) && (right_field == NULL);
}
private:
Item data_field;
binary_tree_node* left_field;
binary_tree_node* right_field;
};
// NON-MEMBER FUNCTIONS for the binary_tree_node:
template
void inorder(Process f, BTNode* node_ptr);
template
void preorder(Process f, BTNode* node_ptr);
template
void postorder(Process f, BTNode* node_ptr);
template
void print(const binary_tree_node* node_ptr, SizeType depth);
template
void tree_clear(binary_tree_node*& root_ptr);
template
binary_tree_node* tree_copy(const binary_tree_node* root_ptr);
template
std::size_t tree_size(const binary_tree_node* node_ptr);
}
#include "bintree.template"
#endif
// FILE: bintree.template
// IMPLEMENTS: The binary_tree node class (see bintree.h for documentation).
#include // Provides assert
#include // Provides NULL, std::size_t
#include // Provides std::setw
#include // Provides std::cout
namespace main_savitch_10
{
template
void inorder(Process f, BTNode* node_ptr)
// Library facilities used: cstdlib
{
if (node_ptr != NULL)
{
inorder(f, node_ptr->left());
f( node_ptr->data());
inorder(f, node_ptr->right());
}
}
template
void postorder(Process f, BTNode* node_ptr)
// Library facilities used: cstdlib
{
if (node_ptr != NULL)
{
postorder(f, node_ptr->left());
postorder(f, node_ptr->right());
f(node_ptr->data());
}
}
template
void preorder(Process f, BTNode* node_ptr)
// Library facilities used: cstdlib
{
if (node_ptr != NULL)
{
f( node_ptr->data());
preorder(f, node_ptr->left());
preorder(f, node_ptr->right());
}
}
template
void print(const binary_tree_node* node_ptr, SizeType depth)
// Library facilities used: iomanip, iostream, stdlib
{
if (node_ptr != NULL)
{
print(node_ptr->right(), depth+1);
std::cout << std::setw(4*depth)<<""; // Indent 4*depth spaces.
std::cout << node_ptr->data()<< std::endl;
print(node_ptr->left(), depth+1);
}
}
template
void tree_clear(binary_tree_node*& root_ptr)
// Library facilities used: cstdlib
{
if (root_ptr != NULL)
{
tree_clear( root_ptr->left());
tree_clear( root_ptr->right());
delete root_ptr;
root_ptr = NULL;
}
}
template
binary_tree_node* tree_copy(const binary_tree_node* root_ptr)
// Library facilities used: cstdlib
{
binary_tree_node *l_ptr;
binary_tree_node *r_ptr;
if (root_ptr == NULL)
return NULL;
else
{
l_ptr = tree_copy( root_ptr->left());
r_ptr = tree_copy( root_ptr->right());
return
new binary_tree_node( root_ptr->data(), l_ptr, r_ptr);
}
}
template
size_t tree_size(const binary_tree_node* node_ptr)
// Library facilities used: cstdlib
{
if (node_ptr == NULL)
return 0;
else
return
1+ tree_size(node_ptr->left())+ tree_size(node_ptr->right());
}
}
now i have qeustions how do I create a .template file and run these codes in my visual studio.

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 Programming Questions!