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

📄 demographuos.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
/* DemoGraphUos
 * ---------------------------------------------
 * Copyright (c) 2002 University of Saskatchewan
 * All Rights Reserved
 * -------------------------------------------- */
 
 package dslib.demo;
 
 import dslib.graph.*;
 import dslib.exception.*;
 import java.io.*;
 
 /** Performs a standard set of tests upon a GraphUos. **/
 
 public class DemoGraphUos 
 {
 	/**  Performs a demo on the Graph passed to it.  Note that
 		it destroys the graph.
		@param g The graph to be demo-ed. */
	public  DemoGraphUos(GraphUos g)
	{
		// place the output in a text file that reflects the class being demonstrated.
		String className = g.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();
		}
		g.fileRead("dslib/demo/graphuosdata.txt");
		out.println("Capacity: " + g.n());
		out.println("Number of vertices: " + g.n());
		out.println("Number of edges: " + g.m());
		g.goIth(4);
		out.println("At Vertex 4: " + g.item()); 
		out.println("4's index: " + g.itemIndex());
		g.goIth(8);
		out.println("At Vertex 8: " + g.item()); 
		out.println("All of the Vertices:");
		g.goFirst();
		while (!g.after())
		{
			out.print(g.item() + ", ");
			g.goForth();
		}
		out.println();
		out.println("All of 1's edges:");
		g.goIth(1);	
		g.eGoFirst((VertexUos)g.item());
		while (!g.eAfter())
		{
			out.print(g.eItem() + "  ");
			g.eGoForth();
		}
		out.println("\nGraph before searches: \n" + g.toString());
		g.goIth(1);
		VertexUos v1 = (VertexUos)g.item(); 
		out.println();
		g.goIth(1);	
		v1 = (VertexUos)g.item();
		g.eNew(v1, v1); 
		g.goIth(2);	
		g.eNew(v1,(VertexUos) g.item());
		g.goIth(3);
		g.eNew(v1, (VertexUos)g.item());
		g.goIth(4);
		g.eNew(v1, (VertexUos)g.item());
		g.goIth(5);
		g.eNew(v1, (VertexUos)g.item());
		g.goIth(6);
		g.eNew(v1, (VertexUos)g.item());
		g.goIth(7);
		g.eNew(v1, (VertexUos)g.item());
		g.goIth(8);
		g.eNew(v1, (VertexUos)g.item());
		out.println("After making edges between 1 and every other vertex including itself: \n" + g.toString());
		out.println("All of 1's edges:");
		g.goIth(1);	
		g.eGoFirst((VertexUos)g.item());
		while (!g.eAfter())
		{
			out.print(g.eItem() + "  ");
			g.eGoForth();
		}
		out.println();
		g.goIth(7);
		g.deleteItem();
		out.println("After deleting Vertex 7: \n" + g.toString());
		g.goIth(3);
		v1 = (VertexUos)g.item(); 
		g.goIth(4);
		VertexUos v2 = (VertexUos)g.item(); 	
		g.eSearch(v1, v2);
		out.println("At Edge 3->4 exists?: " + g.eItemExists());
		out.println("Get Edge 3->4: " + g.eItem().toString());
		g.deleteEItem();
		g.vNew(null);
		out.println("After another vertex insertion: \n" + g.toString());
		try
		{
			g.vNewIth(null, 4);
		} catch (DuplicateItemsUosException x)
		{
			out.println("cannot insert 4 since that index exists");
		}
		out.println("Empty?" + g.isEmpty());
		g.wipeOut();
		out.println("Wiped out--Empty?" + g.isEmpty());
		out.close(); 
	}
}

⌨️ 快捷键说明

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