#include <bits/stdc++.h>
using
namespace
std;
struct
Node {
int
data;
struct
Node *left, *right;
Node(
int
value)
{
data = value;
left = right = NULL;
}
};
void
printInorder(Node* root)
{
if
(root == NULL)
return
;
printInorder(root->left);
cout << root->data << " ";
printInorder(root->right);
}
Node* removeExtraEdge(Node* root,
int
mini,
int
maxi)
{
if
(root == NULL)
return
NULL;
if
(!(root->data < maxi and root->data > mini)) {
return
NULL;
}
root->left
= removeExtraEdge(root->left, mini, root->data);
root->right
= removeExtraEdge(root->right, root->data, maxi);
return
root;
}
Node* removeExtraEdgeInBST(Node* root)
{
return
removeExtraEdge(root, INT_MIN, INT_MAX);
}
int
main()
{
struct
Node* root =
new
Node(7);
root->left =
new
Node(6);
root->right =
new
Node(10);
root->left->left =
new
Node(2);
root->left->right =
new
Node(9);
root->right->left =
new
Node(9);
root->right->right =
new
Node(11);
cout << "Inoder traversal before edge removal : ";
printInorder(root);
cout << endl;
Node* afterChange = removeExtraEdgeInBST(root);
cout << "Inoder traversal after edge removal : ";
printInorder(afterChange);
return
0;
}