Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m having a hard time getting this class going... Basically, I\'m trying to cr

ID: 3624488 • Letter: I

Question

I'm having a hard time getting this class going... Basically, I'm trying to create a BTree with a basic interface. I DO NOT want to balance the tree OR use templates... This is just a basic B-Tree.


class BTree
{
public:
BTree(){}; //Constructor
~BTree(){ }; //Destructor

//Add the number to the correct position in the B-Tree.
//If the value already exists, then do nothing.
void add( int );

//Removes all nodes from the tree, easiest
//way is to use recursive postorder
void clear( );

//Search the tree and remove value if found. If value
//is not found... then do nothing...
void remove( int );

//returns TRUE if the value is in the tree.....
bool contains( int );

//Prints the contents of the tree using an infix tree
//traversal. they should be printed with spaces
//in between each value...
void print( );

};

Explanation / Answer

This should help you out. /*********************************************************************** * Program: * Assignment 13, Binary Tree Class * Summary: Create a class to use for binary trees * ***********************************************************************/ using namespace std; #include #include #include "tree.h" /************************************************************ * default constructor ************************************************************/ BTree::BTree(int data) { setData(data); setLeft(NULL); setRight(NULL); } /************************************************************ * BTree destructor ************************************************************/ BTree::~BTree(void) { delete left; delete right; delete parent; } /************************************************************ * insertLeft ************************************************************/ void BTree::insertLeft(int item) // creates a new node and inserts node to left { BTree* child = new BTree; setLeft(child); left->parent = this; child->setData(item); } /************************************************************ * insertRight ************************************************************/ void BTree::insertRight(int item) // creates a new node and inserts node to right { BTree* child = new BTree; setRight(child); right->parent = this; child->setData(item); } /************************************************************ * get left node ************************************************************/ BTree* BTree::getLeftChild(void) // return the ptr to the left child { return left; } /************************************************************ * get right node ************************************************************/ BTree* BTree::getRightChild(void) // return the ptr to the right child { return right; } /************************************************************ * get parent node ************************************************************/ BTree* BTree::getParent(void) // return parent { return parent; } /************************************************************ * get Data ************************************************************/ int BTree::getData(void) { return data; } /************************************************************ * Set data ************************************************************/ void BTree::setData(int item) { data = item; } /************************************************************ * Set left pointer ************************************************************/ void BTree::setLeft(BTree* tree) { left = tree; } /************************************************************ * Set right pointer ************************************************************/ void BTree::setRight(BTree* tree) { right = tree; } /************************************************************ * prefix traversal ************************************************************/ void BTree::prefix(void) // do prefix traversal { cout infix(); cout postfix(); cout getRightChild() != NULL) dataQ.push((dataQ.front())->getRightChild()); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote