Three-Step Conversion Process for BST

Step 1: Extract Values from Binary Search Tree
First, we extract all values from the binary search tree by traversing it. This gives us an array of values: [10, 2, 7, 8, 4]
Step 2: Sort the Values
Next, we sort the extracted values in ascending order. The sorted array becomes: [2, 4, 7, 8, 10]
Step 3: Replace Values During Inorder Traversal
Finally, we perform an inorder traversal of the tree and replace each node's value with the corresponding value from our sorted array. This converts the original tree into a proper Binary Search Tree while maintaining its structure.