Hello, i am having trouble figuring out inorder traversal in this assignment.
I was given this function definition in the homework i have to declare it.
The problem i am having is how to use pointer to function to traverse the list.
1 2 3 4 5 6 7
void CBSTree<NodeType>::InOrderTraversal(void (*fPtr)(const NodeType&)) const;
void CBSTree<NodeType>::InOrder(const CTreeNode<NodeType> *const nodePtr
,void (*fPtr)(const NodeType&)) const;
//nodePtr is a pointer to a NodeType object (this is a recursive function, initially this points to the root).
//fPtr is a pointer to a non-member function that takes a const reference to a NodeType object as input, and
//returns nothing
I know without the pointer to function parameter it will be like this.
In the example you give, you do in-order traversal and you print out the node's value at the appropriate time. What you need to do is call the fPtr function instead: