Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- struct node
- {
- int value;
- int left;
- int right;
- };
- int high(node* arr, int root)
- {
- if (root<=-1) return 0;
- int left_branch = high(arr, arr[root].right);
- int right_branch = high(arr, arr[root].left);
- if (left_branch > right_branch) return (left_branch + 1);
- else return (right_branch + 1);
- }
- int main()
- {
- fs_base::sync_with_stdio(false);
- Fin.tie(NULL);
- ifstream fin("height.in");
- ofstream fout("height.out");
- int i;
- fin >> i;
- node* binTree = new node[i];
- for (int j = 0; j < i; j++)
- {
- fin >> binTtree[j].value >> binTree[j].left >> binTree[j].right;
- binTree[j].right--;
- binTree[j].left--;
- }
- if (i !=0 ) fout << hight(binTree, 0);
- else fout << 0;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement