Implement a program to find the maximum element in a binary tree.
HardProblem Statement
Implement a program to find the maximum element in a binary tree.
Sample Input
A binary tree with values: 10, 5, 15, 3, 7, 13, 18.
Sample Output
Maximum value: 18
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
#include <iostream>
class TreeNode {
public:
int data;
TreeNode *left;
TreeNode *right;
TreeNode(int val);
};
class BinaryTree {
private:
TreeNode *root;
public:
BinaryTree();
void insert(int value);
int getMax();
};
int main() {
// Logic to demonstrate BinaryTree functionality
return 0;
}
Input
A binary tree with values: 10, 5, 15, 3, 7, 13, 18.
Expected Output
Maximum value: 18