In C++, the struct Node is defined as follows:
struct Node {
int data; // information that is saved in the node
Node *left_child; // holds the address of a node's left child or 0 if there is no left child
Node *right_child; // holds the address of a node's right child or 0 if there is no right child
Node(int = 0, Node * = 0, Node * = 0);
};
The class BinaryTree is also defined, with a private member variable root_ptr that holds the address of the root node in the binary tree or 0 if the binary tree is empty.
Assuming that the following method is being added to the BinaryTree class to display a preorder traversal of a binary tree:
void BinaryTree::displayPreOrder(Node *ptr) const {
// code for preorder traversal
}
To recursively display a preorder traversal of a binary tree, the code that should be placed between the { } in the displayPreOrder method is missing.
For the displayPreOrder method to execute properly, a public version of the method is needed to start the recursive process. The public version of the displayPreOrder method is defined as follows:
void BinaryTree::displayPreOrder() const {
// code to call the private displayPreOrder method with the root_ptr as the starting point
}
The code that should be placed between the { } in the public version of the displayPreOrder method is missing.