testexampletree.java

来自「国外的数据结构与算法分析用书」· Java 代码 · 共 41 行

JAVA
41
字号
import dslib.tree.*;

public class TestExampleTree
{
	ExampleTree t;

	public TestExampleTree()
	{
		t = new ExampleTree();
		makeTree();
		System.out.println("The height of the tree is " + t.height());
		System.out.println("The size (# of nodes) of the tree is " + t.size());
		System.out.println("The number of leaves in the tree is " + t.numberOfLeaves());
		System.out.println("The sum of the values in the tree is " + t.sum());
		System.out.println("The height &  max imbalance of the current tree " + t.maxImbal());
		System.out.println("The max Imbal Ineff of tree is " + t.maxImbalIneff());
	}

	/**	Create the expression tree for 2*a+b*c
		Analysis: Time = (1) */	
	public void makeTree()
	{
		ExampleTree t1, t2, t3, t4, t5, t6;
		t1 = new ExampleTree(null, new Integer(2), null); 
		t2 = new ExampleTree(null, new Integer(7), null); 
		t3 = new ExampleTree(t1, new Integer(4), t2); 
		t5 = new ExampleTree(null, new Integer(9), null); 
		t6 = new ExampleTree(null, new Integer(1), null);
		t4 = new ExampleTree(t5, new Integer(5), t6);
		t = new ExampleTree(t3, new Integer(8), t4);
	
		System.out.println(t.toString());
	}

	public static void main(String args[])
	{
		TestExampleTree c = new TestExampleTree();
	}

}

⌨️ 快捷键说明

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