i have tried this problem many times but unable to do it.
pls provide the complete code for this problem.
Recover binary search tree
@yutikakhanna, here the approach refer below link for the code :-
- Construct inorder traversal of the tree. It should be an almost sorted list where only two elements are swapped.
- Identify two swapped elements x and y in an almost sorted array in linear time.
- Traverse the tree again. Change value x to y and value y to x.
pls provide the complete code along with main function part
@yutikakhanna, there is a error in the problem statement as in the input it is mentioned that first line will have integer denoting size of the input which is not provided to us , so there is another way of taking input refer this , i have commented some parts
In case of any doubt feel free to ask