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

📄 demodictuos.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
/* DemoDictUos
 * ---------------------------------------------
 * Copyright (c) 2002 University of Saskatchewan
 * All Rights Reserved
 * -------------------------------------------- */
 
 package dslib.demo;
 
 import dslib.dictionary.*;
 import dslib.tree.*;
 import java.io.*;
 
 /** A class that demonstrates the use of any DictUos. */
 public class DemoDictUos extends  DemoBasicDictUos
 {

	/**  Performs a demo on the DictUos that is passed to it.  Note that
		this destroys the dictionary.
		@param d The dictionary that we will be demo-ed. */
	public DemoDictUos(DictUos d)
	{
		super(d);
		// place the output in a text file whose name reflects the class being demonstrated
		String className = d.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("DictUos Demo for" + className);
		out.println("Inserting... 23");
		d.insert(new Integer(23));
		out.println("Inserting... 1");
		d.insert(new Integer(1));
		out.println("Inserting... 4");
		d.insert(new Integer(4));
		out.println("Inserting... 23");
		d.insert(new Integer(23));
		out.println("Inserting... 18");		
		d.insert(new Integer(18));
		out.println("Inserting... 2");
		d.insert(new Integer(2));
		out.println("Inserting... 23");
		d.insert(new Integer(23));
		out.println("Inserting... 102");
		d.insert(new Integer(102));
		out.println("Inserting... 23");
		d.insert(new Integer(23));
		out.println("Current contents: " + d);
		out.println("Frequency of 23? " + d.frequency(new Integer(23)));
		out.println("Deleting 23"); 
		d.delete(new Integer(23));
		out.println("Frequency of 23? " + d.frequency(new Integer(23)));
		out.println("Go first");
		d.goFirst();
		out.println("Go forth");
		d.goForth();
		if(d.itemExists())
		{	
			out.println("Delete Item");
			d.deleteItem();
		}
		out.println("Insert 32");
		d.insert(new Integer(32));		
		/* the BinaryTreeUos behaves slightly differently than most 
		     other dictionary classes */
		out.println();
		out.print("Search for 2: ");
		d.search(new Integer(2));
		out.println("Item exists? " + d.itemExists());
		if(d.itemExists())
		{
			out.println(d.item());
			out.println("Delete the Item");
			d.deleteItem();
		}
		int i = 1;
		out.println("Iterate through the list:");
		d.goFirst();
		while(!d.after())
		{
			if(!(d instanceof BinaryTreeUos))
				out.print(d.item() + " ");
			else
				out.print(((BinaryTreeUos)d).linearItem() + " ");
			d.goForth();
		}
		out.println("Current contents: " + d);
		d.goFirst();
		if(!(d instanceof BinaryTreeUos))
			out.println("Delete every item in the dictionary");
		while(!d.after())
		{	
			if(!(d instanceof BinaryTreeUos))
					d.deleteItem();
			else
				d.goForth();
		}
		out.println("Current contents: " + d);
		out.println("Wipe out");
		d.wipeOut();
		out.println("is it empty? " + d.isEmpty());
		out.println("Inserting.. 23");
		d.insert(new Integer(23));
		out.println("Current contents: " + d);		
		out.println("Frequency of 23? " + d.frequency(new Integer(23)));
		out.println("Frequency of 9999? " + d.frequency(new Integer(9999)));
		out.println("Deleting 23");
		d.delete(new Integer(23));
		out.println("is it empty? " + d.isEmpty());
		out.println("that's it");
		out.close();
	}
 	
}

⌨️ 快捷键说明

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