Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<typename T>
- class BinaryTree
- {
- private:
- template<typename T>
- class Node
- {
- public:
- Node* pRight;
- Node* pLeft;
- T data;
- Node(T data = T(), Node* pRight = nullptr, Node* pLeft = nullptr)
- {
- this->data = data;
- this->pRight = pRight;
- this->pLeft = pLeft;
- }
- };
- Node<T>* root;
- size_t size;
- public:
- BinaryTree();
- ~BinaryTree();
- void push(T data, Node*& node);
- void clear();
- int getSize() { return size; }
- T operator[] (const int index);
- };
- template<typename T>
- BinaryTree<T>::BinaryTree()
- {
- size = 0;
- root = nullptr;
- }
- template<typename T>
- BinaryTree<T>::~BinaryTree()
- {
- clear();
- }
- template<typename T>
- void BinaryTree<T>::push(T data, Node*& node)
- {
- if (root == nullptr)
- {
- root = new Node<T>(data);
- }
- else
- {
- Node<T>* current = this->root;
- if (current->data < data)
- push(data, current->pLeft);
- else
- push(data, current->pRight);
- }
- size++;
- }
- template<typename T>
- void BinaryTree<T>::clear()
- {
- while (size)
- {
- //pop_front();
- }
- }
- int main()
- {
- cout << "Hello World!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement