Question: How to add a function pointer to Traversals in a Binary Search Tree in C++. The BST takes in Date Class Objects. The Class is

How to add a function pointer to Traversals in a Binary Search Tree in C++.

The BST takes in Date Class Objects. The Class is made of 3 ints. Days Months and Years. I have made attempts but every time something goes wrong with the syntax or I didn't add something correctly and I can figure out what was done wrong.

I have a Main program that opens a txt file and reads it and inputs into the BST struct thing below. I delete much and of the tree but left the inorder travesals. I should be able to adapt it to the other parts later.

template

struct Node

{

ElemTypedata;

struct Node* left;

struct Node* right;

Node(){

left = nullptr;

right = nullptr;

}

};

template

class BST

{

public:

BST(); /// Default Constructor

void postorder();

///Traversal Post Order

void preorder();

///Traversal PreOrder

void inorder ();

///Traversal InOrder

private:

void inorder(Node *R);

};

template

void BST::inorder()

{

std::cout << "------ Inorder-----" << std::endl;

inorder(root);

std::cout << std::endl;

}

template

void BST::inorder(Node *R)

{

if(R != NULL)

{

inorder(R->left);

std::cout<data<<" ";

inorder(R->right);

}

}

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!