Write a recursive function to print the BST in order void Pr
Write a recursive function to print the BST in order.
void Print( Node * root ) const;
if( root == NULL)
{
}
else
{
Print(root.left);
Print(root.right);
cout << value;
}
Solution
void Print( Node * root ) const;
if( root == NULL)
{
return;
}
else
{
Print(root.left);
cout << root.value; //root value must be print in the middle
Print(root.right);
}
Explanation:
Inorder traversal:left root right
hence first call root.left then root.data and then root.right
