Write C++ code for the following questions: a. Implement the member function isE
ID: 3771181 • Letter: W
Question
Write C++ code for the following questions:
a. Implement the member function isEmpty(). The function returns true is the binary tree is empty, otherwise returns false.
b. Implement the member function inorderTraversal(). The function prints out all the data values of a binary tree by in-order traversal.
c. Implement the destructor ~BTree(). The function deletes all the nodes in a binary tree. The binary tree might be empty(.Hint: It is easier to write the function in a recursive manner. You may declare additional functions if you wish.)
this is a c++ plus.
Explanation / Answer
a)
b)
void BTree::inorder(){
inorder(root);
}
void BTree::inorder(node *ptr)
{
if (root == NULL)
{
cout<<"Tree is empty"<<endl;
return;
}
if (ptr != NULL)
{
inorder(ptr->left);
cout<<ptr->info<<" ";
inorder(ptr->right);
}
}
c)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.