Skip to content

Instantly share code, notes, and snippets.

@orlp
Created November 11, 2014 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orlp/9ce80c8e2e358d38171f to your computer and use it in GitHub Desktop.
Save orlp/9ce80c8e2e358d38171f to your computer and use it in GitHub Desktop.
template<class T>
class TreeNode {
public:
TreeNode(T data, TreeNode<T>* left, TreeNode<T>* right)
: data(data), left(left), right(right) { }
void show() { std::cout << data; }
T get() { return data; }
void set(const T& data) { this->data = data; }
TreeNode<T>* clone() {
return new TreeNode(
data,
left ? left->clone() : nullptr,
right ? right->clone() : nullptr
);
}
friend class Tree<T>;
protected:
T data;
std::unique_ptr<TreeNode<T>> left;
std::unique_ptr<TreeNode<T>> right;
};
template<class T>
class BSTreeNode : public TreeNode<T> {
using TreeNode<T>::TreeNode;
// extra functionality
friend class BSTree<T>;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment