Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename T>
- class Btree
- {
- public:
- Btree()
- {
- }
- Btree(T data)
- {
- this->data = data;
- }
- ~Btree()
- {
- delete this->left;
- delete this->rigth;
- }
- void add(T value)
- {
- if(value >= this->data)
- {
- this->m_add(value, this->rigth);
- }
- else
- {
- this->m_add(value, this->left);
- }
- }
- private:
- T data;
- Btree* left;
- Btree* rigth;
- bool is_exist(Btree* branch)
- {
- return branch ? 1 : 0;
- }
- static void m_add(T value, Btree*& branch)
- {
- if(!branch)
- {
- branch = new Btree<T>;
- branch->data = value;
- return;
- }
- else
- {
- if(value >= branch->data)
- {
- m_add(value, branch->rigth);
- }
- else
- {
- m_add(value, branch->left);
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement