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.
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;
cout has special characters, below are two:
'\t' - tab
'\n' - new line
Hope it helped.