Question: create a tree program with a treeNode.h, Tree.h, and main.cpp, implement both .h files. adding a node and searching functions. in the tree.h ====================================== TreeNode.h

create a tree program with a treeNode.h, Tree.h, and main.cpp, implement both .h files. adding a node and searching functions. in the tree.h

====================================== TreeNode.h

#ifndef TREE_NODE_H #define TREE_NODE_H

template

class TreeNode { public: //Sets the left node of the TreeNode to the given new node void * setLeft(TreeNode * newNode) { this.left = left; }

TreeNode* getLeft() { return left; }

//Sets the right node link of the TreeNode to the given new node. void * setRight(TreeNode* newNode) { this.right = right; }

TreeNode * getRight() { return right; }

//Sets the data in the node to the given data. void setData(T*newData) { this data = newData; }

T *getData() { return this.data; }

private:

TreeNode * left; TreeNode * right; T * data;

}; #endif;

===============================================tree.h

#ifndef TREE_H #define TREE_H

#include "TreeNode.h" template

class Tree { public: Tree() { root = NULL; }

void add(TreeNode*data)

{

}

TreeNode * search(const T& data) { // assume less then or gratter than

}

TreeNode* getRoot() { return root; } private: TreeNode * Root;

}; #endif;

========================================================== main.cpp

#include "Tree.h" #include

int main() { Tree intTree; TreeNode x; x.setData(new int(5)); intTree.add(&x); y.setData(new int(10)); intTree.add(&x); intTree.add(&y); TreeNode found = intTree.serach(intTree.getRoot(), 5); }

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