Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions