like the title
i wanna know how to output a B-tree like that:

****************A
************B******C
********D******E*******F
the struct of B-tree is:
typedef struct node {
            datatype data;
             struct node *lchild, *rchild;
} BTnode,*BTREE
"*" means escape

thanks

>i wanna know how to output a B-tree like that:
Please don't refer to binary trees as B-trees. A B-tree is a separate data structure with significant differences. As for how to print a binary tree like you want, you can do it a number of ways. However, that particular method is rather limiting as you'll have to deal with line wrapping on wider trees. I've found something like this to be more useful as well as simpler to implement:

static void jsw_splaydump_r ( jsw_splaynode_t *root, int level, FILE *out )
{
  int i;

  if ( root == NULL ) {
    for ( i = 0; i < level; i++ )
      fputc ( '\t', out );
    fputs ( "~\n", out );
  }
  else {
    jsw_splaydump_r ( root->link[1], level + 1, out );

    for ( i = 0; i < level; i++ )
      fputc ( '\t', out );
    fprintf ( out, "%d\n", *(int *)root->data );

    jsw_splaydump_r ( root->link[0], level + 1, out );
  }
}

void jsw_splaydump ( jsw_splay_t *tree, FILE *out )
{
  jsw_splaydump_r ( tree->root, 0, out );
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.