Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Node{
- int data;
- Node* root;
- Node* left;
- Node* right;
- int depth = 0;
- public:
- Node(int aData){
- data = aData;
- if (this->root == nullptr) { // If there is no root, the object becomes one.
- this->root = this;
- }
- }
- int more_depth(){
- depth++;
- return depth;
- }
- bool append(Node* n1) {
- if (this->data <= n1->data){
- this->left = n1;
- more_depth();
- return true;
- }
- else{
- this->right = n1;
- more_depth();
- return true;
- }
- return false;
- }
- int GetDepth() { return depth; }
- };
- int main(){
- Node Binary1 (5);
- Node Binary (2);
- Node Binary2 (4);
- Node Binary3 (8);
- Binary1.append(&Binary);
- Binary1.append(&Binary2);
- Binary1.append(&Binary3);
- std::cout << Binary1.GetDepth() << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement