i am currently implementing a binary tree in c++ and i want to traverse it with a function called in_order().
is there any way to pass a function as an argument, so that i can do things like below (without having to write the code to traverse the list more than once)?
struct tree_node; // and so on
class tree; // and so on
void print_node () {
// some stuff here
}
// some other functions
tree mytree();
// insert some nodes
mytree.in_order(print_node);
mytree.in_order(push_node_to_stack);
mytree.in_order(something_else);