I am having trouble implementing a red black tree which uses a template. I have read and understand the purpose but do not know exactly how to implement it into the header file and .cpp file. I was reading in some forums that they must in the same file as the template and others say that they can be separate but in a .hpp file.
header file
enum nodeColor { RED, BLACK };
template <class myType>
struct nodeType
{
myType keyValue;
nodeColor color;
nodeType<myType> *left;
nodeType<myType> *right;
nodeType<myType> *parent;
};
template<class myType>
class redBlackTree
{
public:
redBlackTree() {}
~redBlackTree() {}
void destroyTree();
unsigned int countNodes() const;
unsigned int height() const;
void printTree() const;
void insert(myType);
bool search(myType);
private:
bool search(myType, nodeType<myType> *);
void destroyTree(nodeType<myType> *);
unsigned int countNodes(nodeType<myType> *) const;
unsigned int height(nodeType<myType> *) const;
void printTree(nodeType<myType> *) const;
void rightRotate(nodeType<myType> *);
void leftRotate(nodeType<myType> *);
};
.cpp file
#include "redBlackTree.h"
using namespace std;
redBlackTree::redBlackTree()
{
}
redBlackTree::~redBlackTree()
{
}
void redBlackTree::destroyTree()
{
}
unsigned int redBlackTree::countNodes() const
{
}
unsigned int redBlackTree::height() const
{
}
void redBlackTree::printTree() const
{
}
void redBlackTree::insert(myType)
{
}
bool redBlackTree<myType>::search(myType)
{
}
bool redBlackTree::search(myType, nodeType<myType> *)
{
}
void redBlackTree::destroyTree(nodeType<myType> *)
{
}
unsigned int redBlackTree::countNodes(nodeType<myType> *) const
{
}
unsigned int redBlackTree::height(nodeType<myType> *) const
{
}
void redBlackTree::printTree(nodeType<myType> *) const
{
}
void redBlackTree::rightRotate(nodeType<myType> *)
{
}
void redBlackTree::leftRotate(nodeType<myType> *)
{
}
I also know that I did not include parameters. I am mostly asking for how to approach this so that I can get to coding away.