Skip to content

Instantly share code, notes, and snippets.

@MAGANER
Created April 2, 2021 16:20
Show Gist options
  • Save MAGANER/f764c1cf72da5eeccace673726040972 to your computer and use it in GitHub Desktop.
Save MAGANER/f764c1cf72da5eeccace673726040972 to your computer and use it in GitHub Desktop.
common btree in pure c++
template<class T>
class Node
{
private:
T data;
Node* left, * right;
public:
Node()
{
left = nullptr;
right = nullptr;
}
Node(const T& data)
{
this->data = data;
}
~Node()
{
if (left != nullptr) delete left;
if (right != nullptr) delete right;
}
Node* get_left()
{
return left;
}
Node* get_right()
{
return right;
}
T get_data()
{
return data;
}
void add_leaves(Node<T>* left, Node<T>* right)
{
this->left = left;
this->right = right;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment