如何以树形方式打印B树的键? [英] How to print the keys of a B tree in a tree fashion ?
本文介绍了如何以树形方式打印B树的键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int k = 200 ; // defined in same class as the function print .
public void print ( BNode n )
{
for ( int k = temp ; k>=0 ; k=k-30 )
{
System.out.print(" ");
}
for ( int i = 0 ; i < n.count ; i++ )
{
System.out.print ( n.getValue(i) + " " ) ;
}
if ( !n.leaf )
{
System.out.println ("") ;
for ( int j = 0; j <= n.count ; j++ )
{
temp = temp -- ;
if ( n.getChild(j) != null )
{
print( n.getChild(j) ) ;
}
}
}
}
我无法想到以树形方式打印键值的方法。我希望根节点位于中间,子节点从下一行开始,并将大多数子节点留在根的左侧,依此类推。
请帮助。
我尝试过:
用Java实现代码。
I am not able to think of a way to print the key values in a tree fashion . I want the root node to be at the middle , children nodes starting from the next line and left most child to the left of the root and so on .
Please help .
What I have tried:
Implemented the code in Java .
推荐答案
B树是一种结构,基本上是一个节点,它包含一个值和2个指向2个子节点的指针。诀窍是每棵子树本身就是一棵B树。
这棵B树中的
A B-tree is a structure, basically, a node that contain a value and 2 pointers to 2 child nodes. The trick is that each child tree is a B-tree itself.
in this B-tree
1
2
3
4
5
6
7
1
2
3
本身只是一个B树,只有一个缩进。
A B-树可以有无限的深度,所以最明显的解决方案是使用递归。
你只需要跟踪缩进级别。
is a B-tree by itself with just an indentation.
A B-tree can have an unlimited depth, so the most obvious solution is to use recursion.
you just have to keep track of indentation level.
这篇关于如何以树形方式打印B树的键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文