#include <bits/stdc++.h>
using
namespace
std;
struct
node {
int
data;
struct
node* left;
struct
node* right;
};
struct
node* newNode(
int
data)
{
struct
node* newnode =
new
node();
newnode->data = data;
newnode->left = NULL;
newnode->right = NULL;
return
(newnode);
}
struct
node* insert(
struct
node* node,
int
data)
{
if
(node == NULL)
return
(newNode(data));
else
{
if
(data <= node->data)
node->left = insert(node->left, data);
else
node->right = insert(node->right, data);
return
node;
}
}
int
maxValue(
struct
node* node)
{
struct
node* current = node;
while
(current->right != NULL) {
current = current->right;
}
return
(current->data);
}
int
minValue(
struct
node* node)
{
struct
node* current = node;
while
(current->left != NULL) {
current = current->left;
}
return
(current->data);
}
int
main()
{
struct
node* root = NULL;
root = insert(root, 4);
insert(root, 2);
insert(root, 1);
insert(root, 3);
insert(root, 6);
insert(root, 5);
int
maxNodeValue = maxValue(root);
int
minNodeValue = minValue(root);
cout <<
"Sum of Maximum value and Minimum value in BST is "
<< maxNodeValue + minNodeValue << endl;
cout <<
"Product of Maximum value and Minimum value in BST is "
<< maxNodeValue * minNodeValue;
return
0;
}