Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. class Node{
  5.  
  6.     int data;
  7.     Node* root;
  8.     Node* left;
  9.     Node* right;
  10.     int depth = 0;
  11. public:
  12.     Node(int aData){
  13.         data = aData;
  14.         if (this->root == nullptr) { // If there is no root, the object becomes one.
  15.             this->root = this;
  16.         }
  17.     }
  18.     int more_depth(){
  19.         depth++;
  20.         return depth;
  21.     }
  22.  
  23.     bool append(Node* n1) {
  24.         if (this->data <= n1->data){
  25.             this->left = n1;
  26.             more_depth();
  27.             return true;
  28.         }
  29.         else{
  30.             this->right = n1;
  31.             more_depth();
  32.             return true;
  33.         }
  34.  
  35.         return false;
  36.     }
  37.  
  38.     int GetDepth() { return depth; }
  39. };
  40.  
  41.  
  42. int main(){
  43.  
  44.     Node Binary1 (5);
  45.     Node Binary (2);
  46.     Node Binary2 (4);
  47.     Node Binary3 (8);
  48.     Binary1.append(&Binary);
  49.     Binary1.append(&Binary2);
  50.     Binary1.append(&Binary3);
  51.     std::cout << Binary1.GetDepth() << std::endl;
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement