How to deal with such task. I implemented BST template class which is capable to do operations on simple types like int
, float
etc. Now I want to implement another template class Vector
and add different functionality for this type in BST template class because every comparison in case of Vector
type compare Vector length not just value (in these case two values).
bst.h
#ifndef BSTTREE_BST_H
#define BSTTREE_BST_H
template <class T> class bst {
struct node {
T d;
node *l, *r;
};
node* root;
public:
bst();
~bst();
void freeMemory(node* bstNode);
void insert(T x);
void show();
void show(node* bstNode);
int count(node* bstNode);
node* search(T x);
node* search(node* bstNode, T x);
bool rmv(T x);
};
#include "bst.cpp"
#endif //BSTTREE_BST_H
bst.cpp
#ifndef BSTTREE_BST_CPP
#define BSTTREE_BST_CPP
#include "bst.h"
#include <iostream>
template <class T>
bst<T>::bst() {}
template <class T>
bst<T>::~bst() {}
template <class T>
void bst<T>::freeMemory(bst::node *node) {}
template <class T>
void bst<T>::insert(T x){}
template <class T>
void bst<T>::show() {}
template <class T>
void bst<T>::show(node* root) {}
template <class T>
int bst<T>::count(node* root) {}
template <class T>
typename bst<T>::node* bst<T>::search(T x) {}
template <class T>
typename bst<T>::node* bst<T>::search(node* root, T x) {}
template <class T>
node* bst<T>::rmv(int value, node *parent) {}
#endif //BSTTREE_BST_CPP
I didn't implement methods inner body, because it works just fine and it isn't the task. I know some things in this code are done wrong but I had to follow some rules which in my opinion aren't very clever, but it isn't the point.
I thought about making another template Class vector
in .h/.cpp files and include header to Vector
class in bst.cpp and write there additional functionality for only Vector
class template.
Is it a good idea? Or there is better way to do it (without changing my code very much if it is possible). How to do it?