generaltree.java

来自「java的二叉树的实现参考」· Java 代码 · 共 61 行

JAVA
61
字号

public class GeneralTree
{
/**
 * the root of GeneralTree.
 */
	private GTNode root;

/**
 * constructor of GeneralTree,with a null root.
 */
	public GeneralTree(){
		root=null;
	}

/**
 * constructor of GeneralTree,with a root which item is obj.
 */
	public GeneralTree(Object obj){
		root=new GTNode(obj);
	}

/**
 * remove all node of this tree.
 */
	public void clear(){
		root=null;
	}

/**
 * return the root of this tree.
 */
	public GTNode root(){
		return root;
	}

/*******************fill your code in the following functions.************************/

/**
 * vist this tree in postorder.
 */
	public void visitPostorder(){
		//fill your code here.

	}

/**
 * test code for GTNode.
 */
	public static void main(String[] args) 
	{
		System.out.println("=====test your General tree.====");
		GeneralTree tree=new GeneralTree("A");
		//用GTNode 中的方法实现如图所示(左边)的general tree。

		
		System.out.println("your tree should be : E F G B H I C J K L D A ");
		tree.visitPostorder();
	}
}

⌨️ 快捷键说明

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