#include<bits/stdc++.h>
using namespace std;
class Tree {
public:
int data;
Tree* left = NULL,*right = NULL;
// Constructor initialised
Tree(int x) {
data = x;
left = NULL;
right = NULL;
}
};
int maximum_tree(Tree *root) {
if (root == NULL) return INT_MIN; // If null return minimum number
// Else return the max of number in left subtree, right subtree and the data
return max(root -> data,max(maximum_tree(root->left),maximum_tree(root -> right)));
}
int main() {
Tree *root = new Tree(10);
root -> left = new Tree(22);
root -> right = new Tree(10);
root -> left -> left = new Tree(11);
root -> left -> right = new Tree(10);
cout << maximum_tree(root);
return 0;
}
Login/Signup to comment