📄 binarytree.java
字号:
//二叉树类
class binaryTree
{
private Node root; //根结点
public binaryTree( )
{
root = new Node( 'k');
root.setCount( 0 );
}
public Node getRoot()
{
return root;
}
public void insert( Node r, char c ) //从根点开始插入,默认根结点存的字符为K
{
if( c == r.getChar() )
{
r.addCount();
return ;
}
else if( c < r.getChar() )
{
if( r.getLeft() == null )
{
Node node = new Node( c );
r.setLeft( node );
}
else insert( r.getLeft(), c );
}
else
{
if( r.getRight() == null )
{
Node node = new Node( c );
r.setRight( node );
}
else insert( r.getRight(), c );
}
}
public void print( Node root ) //打印结果,中序遍历
{
if( root == null ) return;
print( root.getLeft() );
if( root.getCount() == 0 )
{}
else System.out.println( root.getChar() + "出现的次数为:" + root.getCount() );
print( root.getRight() );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -