Created
November 11, 2014 14:01
-
-
Save orlp/9ce80c8e2e358d38171f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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