We can use stacks for depth-first traversal.
For binary trees
Note: in-order traversals is only applicable to binary trees (not for N-ary trees)
template<typename Type>
void Binary_tree<Type>::in_order_traversal() const {
if (empty()) {
return;
}
left()->in_order_traversal();
cout << retrieve();
right()->in_order_traversal();
}
In [ ]: