There are three different orders to traverse a binary tree. They are inorder, an
ID: 3826327 • Letter: T
Question
There are three different orders to traverse a binary tree. They are inorder, and preorder, and postorder. Please tell which order is best (necessary) for the following operations: Destroy a binary tree Copy a binary tree Print nodes in alphabetical order Complete the following recursive function. void RevPrint (NodeType*listPtr)//Pre; listPtr is an external pointer to a list.//Post; Values in the list have been printed in reverse order. {if(_______ {______; _____;}} Complete the following recursive function that inserts an item into a binary search tree. void Inser(TreeNode*& tree, ItemType item) {if (______) tree = _____; tree rightarrow right = ____; tree rightarrow left = _____; tree rightarrow info = ______;} else if (_____Explanation / Answer
Please tell which order is best (necessary) for the following operations:
1. Destroy a binary tree.
To destroy a binary tree, first the left child, and then the right child should be
destroyed and finally the root of that node could be destroyed.
So, to destroy a binary tree, postorder traversal is necessary.
2. Copy a binary tree.
To copy a binary tree, first the root should be copied, then the left child, and right
child should be added to that node.
So, to copy a binary tree, preorder traversal is necessary.
3. Print nodes in alphabetical order.
To print the nodes, in ascending order, the left child should be printed first, then the
root and finally a right child.
So, to print in alphabetical order, inorder traversal is necessary.
Complete the following recursive function:
void RevPrint(NodeType* listPtr)
{
if(listPtr != NULL) //If the list is not empty.
{
RevPrint(listPtr->next); //First reverse print all the remaining values.
cout << listPtr->data; //Finally print the current value.
}
}