I'm trying to print binary tree
void print_tree(Node * root,int level )
{
if (root!=NULL)
{
cout<< root->value << endl;
}
//...
}
How can I indent output in order to indent each value with level '-' chars.
You can construct a string to contain a number of repitions of a character:
std::cout << std::string(level, '-') << root->value << std::endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With