⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 demotwowaybinarytreeuos.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
/* DemoTwoWayBinaryTreeUos.java
 * ---------------------------------------------
 * Copyright (c) 2002 University of Saskatchewan
 * All Rights Reserved
 * --------------------------------------------- */
package dslib.demo;

import dslib.tree.*;
import java.io.*;

/**	 A class that demonstrates the use of any TwoWayBinaryTreeUos */
public class DemoTwoWayBinaryTreeUos extends DemoBinaryTreeUos
{
	/**  A demo for testing TwoWayBinaryTreeUos. 
		@param t1 The tree that will be demo-ed.*/
	public DemoTwoWayBinaryTreeUos(TwoWayBinaryTreeUos t1) 
	{	
		super(t1);
		// place the output in a text file that reflects the class being demonstrated.
		String className = t1.getClass().getName();
		className = className.substring(className.lastIndexOf(".")+1);
		PrintWriter out = null;
		try
		{
			out = new PrintWriter(new FileOutputStream("OutputDemo" + className + ".txt", true));
		} catch (Exception e)
		{
			System.err.println("Error creating output file in test routine for " + className);
			e.printStackTrace();
		}
		out.println();
		out.println("Demo For TwoWayBinaryTreeUos");
		t1 = (TwoWayBinaryTreeUos) createInstance(t1, new Integer(4));
		TwoWayBinaryTreeUos t2 = (TwoWayBinaryTreeUos) createInstance(t1, new Integer(21));
		TwoWayBinaryTreeUos t3 = (TwoWayBinaryTreeUos) createInstance(t1, new Integer(33));
		out.println("Go Root");
		t1.goRoot();
		out.println("Inserting..... 21");
	  	out.println("Inserting..... 18");
	  	t2.insertParentLeftGo(new Integer(18));
	  	out.println("Inserting..... 4"); 
		out.println("Inserting..... 1");
	  	t3.insertParentRightGo(new Integer(1));
	  	out.println("Inserting..... 33");
	  	t3.insertLeafRightGo(new Integer(33));
		t1.setLeftSubtree(t2);
		t1.setRightSubtree(t3);
		out.println("Inserting..... 31");	
		t1.insertParentLeftGo(new Integer(31));
		out.println("Inserting..... 12");
		t1.insertParentRightGo(new Integer(12));
		out.println("seraching for 31");
	  	t1.search(new Integer(31));
		out.println("Go to 31's parent");
	  	t1.goParent();	
		while(!t1.before() && t1.linearItemExists())
		{
			out.println("Parent is:" + t1.linearItem());
	  		t1.goParent();
		}
	  	out.close();
	}
}

⌨️ 快捷键说明

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