Question

a function that prints the binary search tree’s all nodes level by level, output statement 50,...

a function that prints the binary search tree’s all nodes level by level, output statement

50, 30, 70, 20, 40, 60, 80

          50 
        /   \ 
        30   70 
       / \   / \ 
      20 40 60 80

  

  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

HERE IS THE IMPLEMENTATION OF THE FUNCTION IN C++

2 4 1 //function defination void print_tree(struct node *root) 3. { //if node is null than return if(root==NULL) 5 return; 6

HERE IS THE CODE

//function defination
void print_tree(struct node *root)
{ //if node is null than return
if(root==NULL)
return;
else
{
//print left child first than right child
if (root.left!=NULL)
cout<<root.left.data<<" ";
if (root.right!=NULL)
cout<<root.right.data<<" ";
//call left child first and than right child
print_tree(root.left);
print_tree(root.right);
return;
}
}

Add a comment
Know the answer?
Add Answer to:
a function that prints the binary search tree’s all nodes level by level, output statement 50,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT