Question: header file #ifndef BINTREE _ H #define BINTREE _ H #include / / Provides NULL and size _ t namespace main _ savitch _ 1
header file
#ifndef BINTREEH
#define BINTREEH
#include Provides NULL and sizet
namespace mainsavitch
template
class binarytreenode
public:
TYPEDEF
typedef Item valuetype;
CONSTRUCTOR
binarytreenode
const Item& initdata Item
binarytreenode initleft NULL,
binarytreenode initright NULL
datafield initdata;
leftfield initleft;
rightfield initright;
MODIFICATION MEMBER FUNCTIONS
Item& data return datafield;
binarytreenode& left return leftfield;
binarytreenode& right return rightfield;
void setdataconst Item& newdata datafield newdata;
void setleftbinarytreenode newleft leftfield newleft;
void setrightbinarytreenode newright rightfield newright;
CONST MEMBER FUNCTIONS
const Item& data const return datafield;
const binarytreenode left const return leftfield;
const binarytreenode right const return rightfield;
bool isleaf const
return leftfield NULL && rightfield NULL;
private:
Item datafield;
binarytreenode leftfield;
binarytreenode rightfield;
;
NONMEMBER FUNCTIONS for the binarytreenode:
template
void inorderProcess f BTNode nodeptr;
template
void preorderProcess f BTNode nodeptr;
template
void postorderProcess f BTNode nodeptr;
template
void printconst binarytreenode nodeptr SizeType depth;
template
void treeclearbinarytreenode& rootptr;
template
binarytreenode treecopyconst binarytreenode rootptr;
template
std::sizet treesizeconst binarytreenode nodeptr;
#include "bintree.template"
#endif
FILE: bintree.template
IMPLEMENTS: The binarytree node class see bintree.h for documentation
#include Provides assert
#include Provides NULL, std::sizet
#include Provides std::setw
#include Provides std::cout
namespace mainsavitch
template
void inorderProcess f BTNode nodeptr
Library facilities used: cstdlib
if nodeptr NULL
inorderf nodeptrleft;
f nodeptrdata;
inorderf nodeptrright;
template
void postorderProcess f BTNode nodeptr
Library facilities used: cstdlib
if nodeptr NULL
postorderf nodeptrleft;
postorderf nodeptrright;
fnodeptrdata;
template
void preorderProcess f BTNode nodeptr
Library facilities used: cstdlib
if nodeptr NULL
f nodeptrdata;
preorderf nodeptrleft;
preorderf nodeptrright;
template
void printconst binarytreenode nodeptr SizeType depth
Library facilities used: iomanip, iostream, stdlib
if nodeptr NULL
printnodeptrright depth;
std::cout std::setwdepth; Indent depth spaces.
std::cout nodeptrdata std::endl;
printnodeptrleft depth;
template
void treeclearbinarytreenode& rootptr
Library facilities used: cstdlib
if rootptr NULL
treeclear rootptrleft;
treeclear rootptrright;
delete rootptr;
rootptr NULL;
template
binarytreenode treecopyconst binarytreenode rootptr
Library facilities used: cstdlib
binarytreenode lptr;
binarytreenode rptr;
if rootptr NULL
return NULL;
else
lptr treecopy rootptrleft;
rptr treecopy rootptrright;
return
new binarytreenode rootptrdata lptr rptr;
template
sizet treesizeconst binarytreenode nodeptr
Library facilities used: cstdlib
if nodeptr NULL
return ;
else
return
treesizenodeptrleft treesizenodeptrright;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
