【问题标题】:How to print the key values of a B tree in a tree fashion in simplest way?如何以最简单的方式以树的方式打印 B 树的键值?
【发布时间】:2018-05-04 13:16:27
【问题描述】:
public void print ( BNode n )  
    {           
        for ( int k = temp ; k>=0 ; k=k-30 ) // temp = 300
        {
            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) ) ;                     
                }                                
            }                
        }        
    }

我正在尝试以预购方式打印 B 树的键值,就像给定 here 的 B 树渲染器一样。

我不想打印箭头,但想要一些好的间距。我已经尝试过我的代码,但我认为它不是正确的方法。

我该怎么做才能做到这一点?

【问题讨论】:

    标签: java tree output b-tree


    【解决方案1】:

    您可以打印制表符 '\t' $currentLevel 的次数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-10
      • 2016-08-16
      • 2014-04-26
      • 1970-01-01
      • 2021-12-05
      相关资源
      最近更新 更多