void print_level(node *root, int space, int level, int currlevel)
{
int i =0;
if ( currlevel == level )
{
for (i = 0; i < space; i++)
printf(" ");
if (root == NULL)
printf(" ");
else
printf("%d",root->data);
for (i = 0; i < space; i++)
printf(" ");
}
else
{
if(!root)
{
print_level(NULL, space, level, currlevel + 1);
print_level(NULL, space, level, currlevel + 1);
}
else
{
print_level(root->left, space, level, currlevel + 1);
print_level(root->right, space, level, currlevel + 1);
}
}
}
void print_tree(node *tree)
{
int hght = height(tree);
int width = (1 << ( hght + 1)) - 1;
int space = width / 2; int i;
for (i = 1; i <= hght; i++)
{
print_level(tree, space, i, 1);
printf("\n\n");
space = space / 2;
}
}