binarysorttreedemo.java

来自「这是数据结构中的描述二叉树的一个JAVA 程序。」· Java 代码 · 共 59 行

JAVA
59
字号
//实例化排序二叉树
package com.fluently.DataStructure.Applications;
import java.io.*;
import com.fluently.DataStructure.*;
public class  BinarySortTreeDemo 
{
	public static void main(String[] args) 
	{
		//建立一个二叉树
		BinarySortTree theBTree =new BinarySortTree();
		//插入结点,第一个接点是根接点
		BinaryTreeNode newNode=new BinaryTreeNode(23);
		theBTree.insertNode(newNode);
		newNode=new BinaryTreeNode(11);
		theBTree.insertNode(newNode);
		newNode=new BinaryTreeNode(6);
		theBTree.insertNode(newNode);
		newNode=new BinaryTreeNode(50);
		theBTree.insertNode(newNode);
		newNode=new BinaryTreeNode(29);
		theBTree.insertNode(newNode);
		newNode=new BinaryTreeNode(100);
		theBTree.insertNode(newNode);
		newNode=new BinaryTreeNode(60);
		theBTree.insertNode(newNode);
		newNode=new BinaryTreeNode(90);
		theBTree.insertNode(newNode);
		
		
		// 中序编历二叉树

		System.out.println("");
		System.out.println("中序编历如下:");
                                theBTree.inOrder(theBTree.root);
		//前序编历二叉树

		System.out.println("");
		System.out.println("前序遍历如下:");
		theBTree.proOrder(theBTree.root);
                                //后序遍历二叉树

		System.out.println("");
		System.out.println("后序遍历如下:");
		theBTree.postOrder(theBTree.root);

		//打印二叉树结点个数
        System.out.println("二叉树结点个数为:");
        System.out.println(theBTree.treeNodeCount());
		
		//打印二叉树深度
		System.out.println("二叉树深度为:");
        System.out.println(theBTree.treeHeight());
		//查找结点
            theBTree.find(60);
	
			
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?