Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. struct node
  5. {
  6.     int value;
  7.     int left;
  8.     int right;
  9. };
  10.  
  11. int high(node* arr, int root)
  12. {
  13.     if (root<=-1) return 0;
  14.  
  15.     int left_branch = high(arr, arr[root].right);
  16.     int right_branch = high(arr, arr[root].left);
  17.  
  18.     if (left_branch > right_branch) return (left_branch + 1);
  19.     else return (right_branch + 1);
  20.  
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26.     fs_base::sync_with_stdio(false);
  27.     Fin.tie(NULL);
  28.     ifstream fin("height.in");
  29. ofstream fout("height.out");
  30.     int i;
  31.     fin >> i;
  32.     node* binTree = new node[i];
  33.     for (int j = 0; j < i; j++)
  34.     {
  35.         fin >> binTtree[j].value >> binTree[j].left >> binTree[j].right;
  36.         binTree[j].right--;
  37.         binTree[j].left--;
  38.     }
  39.  
  40.     if (i !=0 ) fout << hight(binTree, 0);
  41.  
  42.     else fout << 0;
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement