Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void
- Tree::addMethod(Node*& node, const int& value)
- {
- if (node == nullptr)
- node = new Node(value);
- else if (value > node->value)
- addMethod(node->right, value);
- else
- addMethod(node->left, value);
- }
- void
- Tree::deleteMethod(Node* node)
- {
- if (node->left != nullptr)
- deleteMethod(node->left);
- if (node->right != nullptr)
- deleteMethod(node->right);
- delete node;
- }
- void Tree::eraseMethod(const int& value)
- {
- }
- int
- Tree::heightMethod(Node* node)
- {
- if (node == 0)
- return 0;
- int left, right;
- if (node->left != NULL)
- left = heightMethod(node->left);
- else
- left = -1;
- if (node->right != NULL)
- right = heightMethod(node->right);
- else
- right = -1;
- int max = left > right ? left : right;
- return max + 1;
- }
- bool Tree::empty()
- {
- return head == nullptr;
- }
- void Tree::clear()
- {
- deleteMethod(head);
- head = nullptr;
- }
- int Tree::height()
- {
- return heightMethod(head);
- }
- void Tree::add(const int& value)
- {
- addMethod(head, value);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement